Add half arsed user separation
This commit is contained in:
parent
3c792decd6
commit
25bcf4d706
6 changed files with 125 additions and 41 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue