web

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func (h *Handlers) Error(r *http.Request, message string, err error)

Error records an error message into the request context and captures telemetry.

func (*Handlers) GetError

func (h *Handlers) GetError(r *http.Request) string

GetError returns the error message stored in the request context.

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) Mount

func (s *Handlers) Mount(r platform.Router)

Mount registers login, logout, and register routes.

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 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 LoginData

type LoginData = Data

Web view model types used for rendering templates.

type LogoutData

type LogoutData = Data

Web view model types used for rendering templates.

type RegisterData

type RegisterData = Data

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

func NewRenderer(viewFS fs.FS, data map[string]any) *Renderer

NewRenderer creates a new Renderer with the given filesystem and shared data.

func (*Renderer) Load

func (r *Renderer) Load(filename string, data any) vuego.Template

Load loads a template, chaining any layouts declared in template metadata.

func (*Renderer) Login

func (r *Renderer) Login(data LoginData) vuego.Template

func (*Renderer) Logout

func (r *Renderer) Logout(data LogoutData) vuego.Template

func (*Renderer) Register

func (r *Renderer) Register(data RegisterData) vuego.Template

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL