controller

package
v1.7.20 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 25 Imported by: 0

README

Controller Package

This package provides the core HTTP request handling infrastructure for the application.

Act Function

The Act function is the primary entry point for handling HTTP requests. It provides a unified request processing pipeline with telemetry, (optional) authentication, and error handling.

Signature
func Act(key string, w http.ResponseWriter, r *http.Request, f ActFn)

Where ActFn is defined as:

type ActFn func(as *app.State, ps *cutil.PageState) (string, error)
Usage Example
func Home(w http.ResponseWriter, r *http.Request) {
    Act("home", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
		ps.SetTitleAndData(util.AppName, homeContent)
        return Render(r, as, &views.Home{}, ps)
    })
}

PageState Elements

The PageState struct contains numerous properties that influence request processing:

Authentication & Authorization (when enabled)
  • Admin: Whether user has admin privileges (bypasses user.Check)
  • Authed: Authentication status
  • Profile: User profile information
  • Accounts: Associated user accounts
Request Metadata
  • Action: Current action identifier
  • Method: HTTP method
  • URI: Request URL
  • Params: Filtered request parameters
  • RequestBody: Raw request body bytes
Response Control
  • ForceRedirect: Forces redirect to specified path instead of executing handler
  • Title: Page title for rendering
  • Description: Page description
  • Data: Arbitrary data payload for views
UI Configuration
  • Menu: Navigation menu items
  • Breadcrumbs: Navigation breadcrumbs
  • HideHeader: Hides page header
  • HideMenu: Hides navigation menu
  • NoScript: Disables JavaScript
  • Icons: CSS/UI icons to include
  • RootIcon, RootPath, RootTitle: Root navigation configuration
Browser/Platform Detection
  • Browser, BrowserVersion: Browser identification
  • OS, OSVersion: Operating system detection
  • Platform: Platform identifier
Session & State
  • Session: Session data storage
  • Flashes: Flash messages for display
  • Context: Request context for telemetry/cancellation
  • Logger: Request-scoped logger
Performance Tracking
  • Started: Request start time
  • RenderElapsed: View rendering duration
  • ResponseBytes: Response size in bytes

Documentation

Overview

Package controller - Content managed by Project Forge, see [projectforge.md] for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Act added in v0.3.15

func Act(key string, w http.ResponseWriter, r *http.Request, f ActFn)

func ActSite added in v0.3.15

func ActSite(key string, w http.ResponseWriter, r *http.Request, f func(as *app.State, ps *cutil.PageState) (string, error))

func ERsp added in v0.3.15

func ERsp(msg string, args ...any) (string, error)

func FlashAndRedir added in v0.3.15

func FlashAndRedir(success bool, msg string, redir string, ps *cutil.PageState) (string, error)

func Home

func Home(w http.ResponseWriter, r *http.Request)

func NotFoundAction added in v1.1.0

func NotFoundAction(w http.ResponseWriter, r *http.Request)

func NotFoundResponse added in v1.1.0

func NotFoundResponse(w http.ResponseWriter, r *http.Request) func(as *app.State, ps *cutil.PageState) (string, error)

func Options

func Options(w http.ResponseWriter, _ *http.Request)

func Render added in v0.3.15

func Render(r *http.Request, as *app.State, page layout.Page, ps *cutil.PageState, breadcrumbs ...string) (string, error)

func ReturnToReferrer added in v0.3.15

func ReturnToReferrer(msg string, dflt string, ps *cutil.PageState) (string, error)

func SetAppState

func SetAppState(ctx context.Context, a *app.State, logger util.Logger) error

func SetSiteState

func SetSiteState(ctx context.Context, a *app.State, logger util.Logger) error

func Site

func Site(w http.ResponseWriter, r *http.Request)

func Testbed added in v0.8.25

func Testbed(w http.ResponseWriter, r *http.Request)

func Unauthorized

func Unauthorized(w http.ResponseWriter, r *http.Request, reason string) func(as *app.State, ps *cutil.PageState) (string, error)

Types

type ActFn added in v1.2.0

type ActFn func(as *app.State, ps *cutil.PageState) (string, error)

Directories

Path Synopsis
Package cutil - Content managed by Project Forge, see [projectforge.md] for details.
Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Jump to

Keyboard shortcuts

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