1
0

Made NtFound and RobotsTxt handlers a standalone funcs.

This commit is contained in:
Alexander Andreev 2023-05-13 16:29:32 +04:00
parent cd29549a85
commit 472ebf5891
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 6 additions and 6 deletions

View File

@ -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)

View File

@ -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)
}