organize
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func newRouter(db *gorm.DB, cfg Config, pages *Pages, tracker *AccessTracker) http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
fs := http.FileServer(http.Dir("static"))
|
||||
mux.Handle("GET /css/", fs)
|
||||
mux.Handle("GET /js/", fs)
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", fs))
|
||||
mux.Handle("GET /qts/", http.StripPrefix(
|
||||
"/qts/",
|
||||
http.FileServer((http.Dir("qts"))),
|
||||
))
|
||||
mux.HandleFunc("GET /{$}", homeHandler(pages, cfg))
|
||||
mux.HandleFunc("GET /tos", staticPage(pages, "tos.html"))
|
||||
mux.HandleFunc("GET /privacy", staticPage(pages, "privacy.html"))
|
||||
mux.HandleFunc("GET /faq", faqHandler(pages, cfg))
|
||||
uploads := http.NewServeMux()
|
||||
uploads.HandleFunc("GET /{id}", contentHandler(db, cfg, tracker))
|
||||
uploads.HandleFunc("GET /{id}/info", contentInfoHandler(db, tracker))
|
||||
mux.Handle("/", uploads)
|
||||
mux.HandleFunc("POST /upload", uploadHandler(db, cfg, pages))
|
||||
mux.HandleFunc("PUT /upload", uploadHandler(db, cfg, pages))
|
||||
mux.HandleFunc("DELETE /{id}", deleteHandler(db, cfg))
|
||||
mux.HandleFunc("POST /{id}/delete", deleteHandler(db, cfg))
|
||||
mux.HandleFunc("GET /health", health)
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user