Made NtFound and RobotsTxt handlers a standalone funcs.
This commit is contained in:
parent
cd29549a85
commit
472ebf5891
@ -83,8 +83,8 @@ func main() {
|
|||||||
hand := http.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize)
|
hand := http.NewUploadHandlers(config, logErr, logUpload, logDownload, logDelete, &uploadDirSize)
|
||||||
srv := http.NewHttpServer()
|
srv := http.NewHttpServer()
|
||||||
|
|
||||||
srv.SetNotFoundHandler(hand.NotFound)
|
srv.SetNotFoundHandler(http.NotFound)
|
||||||
srv.GET("/robots.txt", hand.RobotsTxt)
|
srv.GET("/robots.txt", http.RobotsTxt)
|
||||||
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())
|
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())
|
||||||
srv.GET("/", hand.Index)
|
srv.GET("/", hand.Index)
|
||||||
srv.POST("/", hand.Upload)
|
srv.POST("/", hand.Upload)
|
||||||
|
@ -158,7 +158,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stat, err := os.Stat(path)
|
stat, err := os.Stat(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
h.NotFound(w, r)
|
NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
h.NotFound(w, r)
|
NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusNoContent)
|
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)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
if !strings.Contains(r.UserAgent(), "curl") {
|
if !strings.Contains(r.UserAgent(), "curl") {
|
||||||
web.Error404(utils.MainSite(r.Host), w)
|
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")
|
data, _ := web.AssetsGetFile("robots.txt")
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user