rework template rendering, cache parsed templates

adapt error wrapping principle
This commit is contained in:
Johannes 2022-09-24 15:01:33 +02:00
parent 7a1448d6f9
commit f04396809d
21 changed files with 175 additions and 82 deletions

15
main.go
View file

@ -11,6 +11,7 @@ import (
"officeHours/controllers"
"officeHours/repositories"
"officeHours/sqldb"
"officeHours/templating"
"os"
)
@ -20,10 +21,6 @@ func main() {
log.SetOutput(logwriter)
}
if controllers.TemplateError != nil {
log.Fatalf("Error parsing templates: %s", controllers.TemplateError.Error())
}
configFile := flag.String(
"config",
"config/config.json",
@ -42,10 +39,16 @@ func main() {
// serve static files
staticHandler := http.FileServer(http.Dir("./static"))
// parse templates
if err = templating.InitTemplates(); err != nil {
log.Print(err.Error())
log.Fatal(">>>\nFatal error occurred, aborting program\n<<<\n")
}
// database connection
db, err := sqldb.Connect(conf)
if err != nil {
log.Fatalf(err.Error())
log.Print(err.Error())
log.Fatal(">>>\nFatal error occurred, aborting program\n<<<\n")
}
// Create repos
roomRepo := repositories.NewRoomRepo(db)