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)
|
||||
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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user