package web import ( "net/http" "tug/internal/transport/web/text" ) func (k *Kit) AccountPages(base []Route, overview http.Handler, extra ...Route) []Route { if overview == nil { panic("web: the account pages need an overview") } out := make([]Route, 0, len(base)+len(extra)+1) for _, rt := range base { switch { case rt.Path == LogoutPath && rt.Method == http.MethodGet && !rt.Prefix: rt.Handler = k.accountLogoutPage() out = append(out, rt) case rt.Path != "/" || rt.Prefix: out = append(out, rt) case rt.Method != http.MethodGet: panic("web: the account pages own /, and the base declares " + rt.Method + " /") } } out = append(out, Route{Method: http.MethodGet, Path: "/", Handler: overview}) return append(out, extra...) } func (k *Kit) accountLogoutPage() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p, ok := k.principal(w, r) if !ok { return } c := logoutConfirm(p) c.Also, c.AlsoButton = BrowserLogoutPath, text.AccountBrowserSignOut k.RenderConfirm(w, r, c) }) }