exit if unable to load template at init

This commit is contained in:
rmanach
2025-01-03 09:32:27 +01:00
parent 731f1bc5b5
commit 0d48db8b94
4 changed files with 6 additions and 30 deletions
-10
View File
@@ -166,11 +166,6 @@ func extractBookForm(r *http.Request) BookForm {
func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionStore) {
uploadForm := templates.GetUploadForm()
if uploadForm == nil {
log.Error().Msg("unable to load upload form")
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
return
}
if !s.IsLogged(r) {
buf := bytes.NewBufferString("")
@@ -238,11 +233,6 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
func getUploadFile(w http.ResponseWriter, _ *http.Request) {
uploadForm := templates.GetUploadForm()
if uploadForm == nil {
log.Error().Msg("unable to load upload form")
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
return
}
buf := bytes.NewBufferString("")
if err := uploadForm.Execute(buf, &BookForm{}); err != nil {
+2 -1
View File
@@ -4,6 +4,7 @@ import (
_ "embed"
"html/template"
"mime/multipart"
"os"
"strconv"
"strings"
"sync"
@@ -40,7 +41,7 @@ var GetUploadForm = sync.OnceValue[*template.Template](func() *template.Template
tmpl, err := template.New("uploadForm").Funcs(funcMap).Parse(form)
if err != nil {
log.Err(err).Msg("unable to parse upload form")
return nil
os.Exit(1)
}
return tmpl
})