package internal import ( "html/template" "net/http" "time" "github.com/vcraescu/go-paginator" "github.com/justinas/nosurf" "git.mills.io/prologic/spyda" ) type Meta struct { Title string Description string UpdatedAt string Image string Author string URL string Keywords string } type Context struct { Config string Debug bool BaseURL string InstanceName string SoftwareVersion string SearchQuery string SearchPrompt string Username string User *User Tokens []*Token Authenticated bool IsAdmin bool Error bool Message string Theme string Commit string Page string Content template.HTML Title string Meta Meta CachedURL string CachedTitle string CachedContent string SearchTook time.Duration Results Results Pager *paginator.Paginator // Reset Password Token PasswordResetToken string // CSRF Token CSRFToken string } func NewContext(conf *Config, db Store, req *http.Request) *Context { ctx := &Context{ Debug: conf.Debug, BaseURL: conf.BaseURL, InstanceName: conf.Name, SoftwareVersion: spyda.FullVersion(), SearchPrompt: conf.RandomSearchPrompt(), Commit: spyda.Commit, Theme: conf.Theme, Title: "", Meta: Meta{ Title: DefaultMetaTitle, Author: DefaultMetaAuthor, Keywords: DefaultMetaKeywords, Description: conf.Description, }, } ctx.CSRFToken = nosurf.Token(req) return ctx }