tfstated/pkg/webui/index.go

35 lines
764 B
Go
Raw Normal View History

package webui
import (
2025-01-22 00:46:49 +01:00
"fmt"
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/model"
)
2025-01-26 00:04:38 +01:00
type Page struct {
IsAdmin bool
LightMode bool
Precedent string
Section string
Title string
2025-01-26 00:04:38 +01:00
}
func makePage(r *http.Request, page *Page) *Page {
account := r.Context().Value(model.AccountContextKey{}).(*model.Account)
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) {
2025-01-22 00:46:49 +01:00
if r.URL.Path == "/" {
http.Redirect(w, r, "/states", http.StatusFound)
} else {
errorResponse(w, http.StatusNotFound, fmt.Errorf("Page not found"))
}
})
}