Documentation
¶
Index ¶
- Variables
- type Data
- type Handlers
- func (h *Handlers) Error(r *http.Request, message string, err error)
- func (h *Handlers) GetError(r *http.Request) string
- func (h *Handlers) Login(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) LoginView(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Logout(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) LogoutView(w http.ResponseWriter, r *http.Request)
- func (s *Handlers) Mount(r platform.Router)
- func (h *Handlers) Register(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) RegisterView(w http.ResponseWriter, r *http.Request)
- type Links
- type LoginData
- type LogoutData
- type RegisterData
- type Renderer
Constants ¶
This section is empty.
Variables ¶
var Funcs = vuego.FuncMap{ "postDate": func(val any) any { layoutStr := "2006/01/02 15:04" switch t := val.(type) { case time.Time: return t.Format(layoutStr) case string: if parsed, err := time.Parse(time.RFC3339, t); err == nil { return parsed.Format(layoutStr) } } return val }, "readingTime": func(content string) string { words := len(strings.Fields(content)) minutes := words / 200 if words%200 != 0 { minutes++ } if minutes <= 2 { return "a few minutes" } return fmt.Sprintf("%d minutes", minutes) }, "metaTitle": func(title string) string { return title }, "metaDescription": func(description string) string { return description }, "metaOGImage": func(in string) string { return in }, "getCss": func(string) string { return "" }, "getJs": func(string) string { return "" }, "json": func(in any) (string, error) { b, err := json.MarshalIndent(in, "", " ") return string(b), err }, }
Funcs provides template helper functions for vuego rendering.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
SessionUser *model.User `json:"sessionUser"`
User string `json:"user"`
Email string `json:"email"`
Username string `json:"username"`
ErrorMessage string `json:"errorMessage"`
FullName string `json:"fullName"`
Links Links `json:"links"`
}
Web view model types used for rendering templates.
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers encapsulates what we need to get from the handler.
func NewHandlers ¶
func NewHandlers(u *storage.UserStorage, s *storage.SessionStorage, viewFS fs.FS) *Handlers
NewHandlers takes in required dependencies to support the MVC framework. Context should be passed from Start() to access platform options.
func (*Handlers) Error ¶
Error records an error message into the request context and captures telemetry.
func (*Handlers) Login ¶
func (h *Handlers) Login(w http.ResponseWriter, r *http.Request)
Login handles user authentication via HTML form submission.
func (*Handlers) LoginView ¶
func (h *Handlers) LoginView(w http.ResponseWriter, r *http.Request)
LoginView renders login.tpl when no valid session exists, or logout.tpl with the full user model when a valid session is found.
func (*Handlers) Logout ¶
func (h *Handlers) Logout(w http.ResponseWriter, r *http.Request)
Logout deletes the session cookie and optionally the session in storage.
func (*Handlers) LogoutView ¶
func (h *Handlers) LogoutView(w http.ResponseWriter, r *http.Request)
LogoutView just wraps LoginView. The view changes based on if the user is logged in already, allowing them to log in or out.
func (*Handlers) Register ¶
func (h *Handlers) Register(w http.ResponseWriter, r *http.Request)
Register handles creating a new user and starting a session via HTML form submission.
func (*Handlers) RegisterView ¶
func (h *Handlers) RegisterView(w http.ResponseWriter, r *http.Request)
RegisterView renders the registration page.
type Links ¶
type Links struct {
Login string `json:"login"`
Logout string `json:"logout"`
Register string `json:"register"`
Recover string `json:"recover"`
}
Web view model types used for rendering templates.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer handles page and layout rendering with vuego templates.
func NewRenderer ¶
NewRenderer creates a new Renderer with the given filesystem and shared data.