From 472ebf5891029592672596572ae7f4599733294f Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 13 May 2023 16:29:32 +0400 Subject: [PATCH] Made NtFound and RobotsTxt handlers a standalone funcs. --- cmd/dwelling-upload/main.go | 4 ++-- internal/http/handlers.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/dwelling-upload/main.go b/cmd/dwelling-upload/main.go index 2556133..1b3e6f1 100644 --- a/cmd/dwelling-upload/main.go +++ b/cmd/dwelling-upload/main.go @@ -83,8 +83,8 @@ func main() { hand := http.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize) srv := http.NewHttpServer() - srv.SetNotFoundHandler(hand.NotFound) - srv.GET("/robots.txt", hand.RobotsTxt) + srv.SetNotFoundHandler(http.NotFound) + srv.GET("/robots.txt", http.RobotsTxt) srv.ServeStatic("/assets/*filepath", hand.AssetsFS()) srv.GET("/", hand.Index) srv.POST("/", hand.Upload) diff --git a/internal/http/handlers.go b/internal/http/handlers.go index eca9acb..1853bca 100644 --- a/internal/http/handlers.go +++ b/internal/http/handlers.go @@ -158,7 +158,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) { stat, err := os.Stat(path) if os.IsNotExist(err) { - h.NotFound(w, r) + NotFound(w, r) return } @@ -194,7 +194,7 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) { _, err := os.Stat(path) if os.IsNotExist(err) { - h.NotFound(w, r) + NotFound(w, r) return } @@ -212,7 +212,7 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } -func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) { +func NotFound(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) if !strings.Contains(r.UserAgent(), "curl") { web.Error404(utils.MainSite(r.Host), w) @@ -221,7 +221,7 @@ func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) { } } -func (h *UploadHandlers) RobotsTxt(w http.ResponseWriter, r *http.Request) { +func RobotsTxt(w http.ResponseWriter, r *http.Request) { data, _ := web.AssetsGetFile("robots.txt") w.Write(data) }