// Copyright (C) 2021 Marius Schellenberger package server import ( "embed" "errors" "git.giftfish.de/ston1th/docstore/pkg/log" "html/template" "io/fs" ) //go:embed templates/* var templates embed.FS func (s *HTTPServer) loadTemplates() { var fatal bool s.templ = make(map[string]*template.Template) s.res = make(map[string][]byte) tfs, err := fs.Sub(templates, "templates") if err != nil { log.Fatal("parse: ", err) } parse := func(html ...string) (temp *template.Template) { var err error temp, err = template.ParseFS(tfs, html...) if err != nil { log.Println("parse:", err) fatal = true } return } // register s.templ["registerHandler"] = parse("index.html", "menu.html", "register.html") s.templ["dirHandler"] = parse("index.html", "menu.html", "dir.html") s.templ["fileHandler"] = parse("index.html", "menu.html", "file.html") s.templ["uploadHandler"] = parse("index.html", "menu.html", "upload.html") s.templ["newDirHandler"] = parse("index.html", "menu.html", "newDir.html") s.templ["moveHandler"] = parse("index.html", "menu.html", "move.html") s.templ["enoentHandler"] = parse("index.html", "menu.html", "enoent.html") s.templ["deleteHandler"] = parse("index.html", "menu.html", "delete.html") s.templ["notFoundHandler"] = parse("index.html", "menu.html", "notFound.html") s.templ["forbiddenHandler"] = parse("index.html", "menu.html", "forbidden.html") s.templ["iseHandler"] = parse("index.html", "menu.html", "ise.html") s.templ["loginHandler"] = parse("index.html", "menu.html", "login.html") s.templ["loginTotpHandler"] = parse("index.html", "menu.html", "loginTotp.html") s.templ["searchHandler"] = parse("index.html", "menu.html", "search.html") s.templ["userEditHandler"] = parse("index.html", "menu.html", "userEdit.html") // totp s.templ["userTotpHandler"] = parse("index.html", "menu.html", "userTotp.html") // tags s.templ["tagsHandler"] = parse("index.html", "menu.html", "tagsList.html") s.templ["tagsNewHandler"] = parse("index.html", "menu.html", "tagsNew.html") s.templ["tagsEditHandler"] = parse("index.html", "menu.html", "tagsEdit.html") s.templ["tagsDelHandler"] = parse("index.html", "menu.html", "tagsDel.html") // stats s.templ["statsHandler"] = parse("index.html", "menu.html", "stats.html") // logs s.templ["logsHandler"] = parse("index.html", "menu.html", "logs.html") if fatal { log.Fatal("parse: ", errors.New("parsing templates failed")) } }