Files
worker/internal/webapp/page_data.go
Gleb Tv 2c7a0236da feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
2026-07-13 17:55:14 +03:00

41 строка
1.0 KiB
Go

package webapp
import (
"net/http"
"time"
)
// basePageData is the struct every page template receives (embedded
// into the per-page struct). The shared layout looks up Title,
// IsLogin, CSRFToken, Version, BuildDate, and StartedAt from here so
// handlers do not need to repeat those fields on every page.
type basePageData struct {
Title string
IsLogin bool
CSRFToken string
Version string
BuildDate string
StartedAt time.Time
}
// newBasePage builds the common fields. isLogin is true for the
// login page so the layout can hide the navigation; csrfToken is the
// empty string when isLogin is true (there is no session yet).
func (s *Server) newBasePage(_ *http.Request, title string, sess *Session) basePageData {
return basePageData{
Title: title,
IsLogin: sess == nil,
CSRFToken: tokenOrEmpty(sess),
Version: s.deps.Version,
BuildDate: s.deps.BuildDate,
StartedAt: s.deps.StartedAt,
}
}
func tokenOrEmpty(sess *Session) string {
if sess == nil {
return ""
}
return sess.CSRFToken
}