tfstated/pkg/webui/index.go
Julien Dessaux 895615ad6e
All checks were successful
main / main (push) Successful in 7m12s
main / publish (push) Has been skipped
main / deploy (push) Has been skipped
chore(webui): rewrite the web session code again while preparing for csrf tokens
#60
2025-04-30 22:31:25 +02:00

29 lines
595 B
Go

package webui
import (
"fmt"
"net/http"
"git.adyxax.org/adyxax/tfstated/pkg/model"
)
type Page struct {
Section string
Session *model.Session
Title string
}
func makePage(r *http.Request, page *Page) *Page {
page.Session = r.Context().Value(model.SessionContextKey{}).(*model.Session)
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"))
}
})
}