diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index cf4b41b..b732ed8 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -23,6 +23,10 @@ var defaultAmberOptions = amber.Options{PrettyPrint: false, LineNumbers: false} var compiledTemplates map[string]*template.Template +type NotFoundData struct { + MainSite string +} + type IndexData struct { MainSite string FileMaxSz string @@ -176,7 +180,6 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) { } w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", name)) - // w.Header().Add("Content-Type", "application/octet-stream") fd, err := os.Open(path) if err != nil { @@ -190,3 +193,13 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) { http.ServeContent(w, r, path, stat.ModTime(), fd) } + +func (h *UploadHandlers) NotFound(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) + if err := compiledTemplates["404"].Execute(w, NotFoundData{ + MainSite: utils.MainSite(r.Host), + }); err != nil { + w.WriteHeader(http.StatusInternalServerError) + h.logErr.Fatalln("failed to execute 404 template:", err) + } +}