package dashboard import ( "html/template" "net/http" "github.com/xlgmokha/x/pkg/context" "github.com/xlgmokha/x/pkg/x" "gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/domain" ) var CurrentUserKey context.Key[*domain.User] = context.Key[*domain.User]("current_user") type Controller struct { } func New() *Controller { return &Controller{} } func (c *Controller) MountTo(mux *http.ServeMux) { mux.HandleFunc("GET /dashboard", c.Show) } func (c *Controller) Show(w http.ResponseWriter, r *http.Request) { currentUser := CurrentUserKey.From(r.Context()) if x.IsZero(currentUser) { http.Redirect(w, r, "/", http.StatusFound) return } w.WriteHeader(http.StatusOK) w.Header().Add("Content-Type", "text/html") const tpl = ` SparkleLab - {{.Title}}
{{range .Sparkles}}
{{ . }}
{{else}}
No Sparkles
{{end}}
` t := x.Must(template.New("show").Parse(tpl)) data := struct { Title string Sparkles []string }{ Title: "SparkleLab", Sparkles: []string{}, } t.Execute(w, data) }