From 37872dda878014db539c217b01729cace091bdd2 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 7 Sep 2024 22:30:17 +0300 Subject: [PATCH] Migrate misc --- misc/about.go | 14 +++++++++----- misc/handlers.go | 3 ++- misc/views.go | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/misc/about.go b/misc/about.go index 36c392a..16d1164 100644 --- a/misc/about.go +++ b/misc/about.go @@ -1,13 +1,15 @@ package misc import ( + "log/slog" + "os" + "strings" + "text/template" // sic! TODO: make it html/template after the template library migration + "github.com/bouncepaw/mycorrhiza/internal/cfg" "github.com/bouncepaw/mycorrhiza/internal/user" "github.com/bouncepaw/mycorrhiza/internal/version" "github.com/bouncepaw/mycorrhiza/l18n" - "log" - "strings" - "text/template" // sic! ) type L10nEntry struct { @@ -95,7 +97,8 @@ func AboutHTML(lc *l18n.Localizer) string { } temp, err := template.New("about wiki").Funcs(template.FuncMap{"get": get}).Parse(aboutTemplateString) if err != nil { - log.Fatalln(err) + slog.Error("Failed to parse About template", "err", err) + os.Exit(1) } data := aboutData data.Version = version.Short @@ -112,7 +115,8 @@ func AboutHTML(lc *l18n.Localizer) string { var out strings.Builder err = temp.Execute(&out, data) if err != nil { - log.Println(err) + slog.Error("Failed to execute About template", "err", err) + os.Exit(1) } return out.String() } diff --git a/misc/handlers.go b/misc/handlers.go index e282ee4..a8f0239 100644 --- a/misc/handlers.go +++ b/misc/handlers.go @@ -4,6 +4,7 @@ package misc import ( "io" "log" + "log/slog" "math/rand" "mime" "net/http" @@ -133,7 +134,7 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) { map[string]string{}, )) if err != nil { - log.Println(err) + slog.Error("Failed to write About template", "err", err) } } diff --git a/misc/views.go b/misc/views.go index 99f83ff..2cbd389 100644 --- a/misc/views.go +++ b/misc/views.go @@ -2,6 +2,7 @@ package misc import ( "embed" + "github.com/bouncepaw/mycorrhiza/internal/hyphae" "github.com/bouncepaw/mycorrhiza/web/viewutil" )