exit if unable to load template at init
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user