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 }