lockserver/httpserver/templates.go

33 lines
766 B
Go

package httpserver
import (
"io"
"git.janky.solutions/finn/lockserver/frontend"
echo "github.com/labstack/echo/v4"
)
type Template struct {
}
type templateData struct {
BaseURL string
Username string
UserDisplayName string
Data any
}
func buildTemplateData(c echo.Context, data any) templateData {
headers := c.Request().Header
return templateData{
BaseURL: headers.Get("X-Ingress-Path"),
Username: headers.Get("X-Remote-User-Name"),
UserDisplayName: headers.Get("X-Remote-User-Display-Name"),
Data: data,
}
}
func (t *Template) Render(w io.Writer, name string, data any, c echo.Context) error {
return frontend.Templates.ExecuteTemplate(c.Response(), name, buildTemplateData(c, data))
}