From 38e6813d119a1b2f8646ca7fc195d1337c533715 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Fri, 26 May 2023 04:30:29 +0400 Subject: [PATCH] Made use of my own httpr router in main. --- cmd/dwelling-upload/main.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/cmd/dwelling-upload/main.go b/cmd/dwelling-upload/main.go index c897297..5e1599c 100644 --- a/cmd/dwelling-upload/main.go +++ b/cmd/dwelling-upload/main.go @@ -4,6 +4,7 @@ import ( "dwelling-upload/internal/http" "dwelling-upload/pkg/utils" "dwelling-upload/pkg/watcher" + "dwelling-upload/web" "flag" "fmt" "log" @@ -14,6 +15,8 @@ import ( "path" "strings" "syscall" + + "git.arav.su/Arav/httpr" ) var listenAddress *string = flag.String("listen", "/var/run/dwelling-upload/sock", "listen address (ip:port|unix_path)") @@ -88,21 +91,24 @@ func main() { hand := http.NewUploadHandlers(logFile, *uploadDir, &uploadDirSize, string(hashSalt), *keepFileForHours, *limitStorage, *limitFileSize) - srv := http.NewHttpServer() - srv.SetNotFoundHandler(func(w nethttp.ResponseWriter, r *nethttp.Request) { + r := httpr.New() + + r.NotFoundHandler = func(w nethttp.ResponseWriter, r *nethttp.Request) { http.Error(w, r, nethttp.StatusNotFound, "") - }) + } - srv.ServeStatic("/assets/*filepath", http.AssetsFS()) - srv.GET("/robots.txt", http.RobotsTxt) - srv.GET("/favicon.svg", http.Favicon) + r.Handler(nethttp.MethodGet, "/", hand.Index) + r.Handler(nethttp.MethodPost, "/", hand.Upload) + r.Handler(nethttp.MethodGet, "/:hash/:name", hand.Download) + r.Handler(nethttp.MethodPost, "/delete", hand.Delete) + r.Handler(nethttp.MethodDelete, "/:hash", hand.Delete) - srv.GET("/", hand.Index) - srv.POST("/", hand.Upload) - srv.POST("/delete", hand.Delete) - srv.GET("/f/:hash/:name", hand.Download) - srv.DELETE("/:hash", hand.Delete) + r.ServeStatic("/assets/*filepath", web.Assets()) + r.Handler(nethttp.MethodGet, "/robots.txt", http.RobotsTxt) + r.Handler(nethttp.MethodGet, "/favicon.svg", http.Favicon) + + srv := http.NewHttpServer(r) if err := srv.Start(network, *listenAddress); err != nil { log.Fatalln("failed to start a server:", err)