tfstated/pkg/webui/index.go
Julien Dessaux 3bb5e735c6
All checks were successful
main / main (push) Successful in 3m13s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped
chore(webui): rewrite all the web session code
#60
2025-04-29 01:25:11 +02:00

39 lines
877 B
Go

package webui
import (
"fmt"
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/model"
"go.n16f.net/uuid"
)
type Page struct {
AccountId *uuid.UUID
IsAdmin bool
LightMode bool
Section string
Title string
}
func makePage(r *http.Request, page *Page) *Page {
accountCtx := r.Context().Value(model.AccountContextKey{})
if accountCtx != nil {
account := accountCtx.(*model.Account)
page.AccountId = &account.Id
page.IsAdmin = account.IsAdmin
}
settings := r.Context().Value(model.SettingsContextKey{}).(*model.Settings)
page.LightMode = settings.LightMode
return page
}
func handleIndexGET() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
http.Redirect(w, r, "/states", http.StatusFound)
} else {
errorResponse(w, r, http.StatusNotFound, fmt.Errorf("Page not found"))
}
})
}