Add half arsed user separation

This commit is contained in:
Maximilian Friedersdorff 2025-07-30 13:41:03 +01:00
parent 3c792decd6
commit 25bcf4d706
6 changed files with 125 additions and 41 deletions

View file

@ -6,11 +6,12 @@ import (
"path/filepath"
"forgejo.gwairfelin.com/max/gonotes/internal/conf"
"forgejo.gwairfelin.com/max/gonotes/internal/middleware"
)
type Ctx map[string]any
func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
func RenderTemplate(w http.ResponseWriter, r *http.Request, tmpl string, context Ctx) error {
var err error
files := []string{
filepath.Join("templates", "base.tmpl.html"),
@ -26,6 +27,12 @@ func RenderTemplate(w http.ResponseWriter, tmpl string, context any) error {
}
t, err := template.ParseFS(conf.Templates, files...)
if err != nil {
return err
}
context["user"] = r.Context().Value(middleware.ContextKey("user")).(string)
err = t.ExecuteTemplate(w, "base", context)
return err
}