site

package module
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

README ¶

tinywasm/site

Project Badges

Site rendering engine for Go (WASM-friendly).

A lightweight rendering layer built on top of tinywasm/dom, designed to generate web pages with minimal overhead. Provides small, efficient primitives for composing views, routing, and rendering UI structures while keeping WebAssembly binaries tiny and dependency-free.

📚 Documentation

  1. Architecture: High-level overview and design goals.
  2. Modules: Routes and modular structure.
  3. Components: UI building blocks and icons.
  4. Routing: Typed routing and path generation.
  5. Access Control: Security and SSR vs SPA logic.
  6. Assets: Bundling and resource management.

🔄 Migration

See MIGRATION.md for changes in API (v0.2+).

✨ New Features

  • Nested Routes: Support for #module/param/action.
  • Lifecycle Hooks: BeforeNavigateAway and AfterNavigateTo.
  • Simplified API: site.Serve(":8080") and site.Mount("app").
  • Navigation Component: Navigation UI moved to components/nav.

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func Mount ¶ added in v0.0.5

func Mount(mux *http.ServeMux) error

Mount registers the site handlers with the provided mux and prepares assets.

func RegisterHandlers ¶

func RegisterHandlers(handlers ...any) error

RegisterHandlers registers all handlers with site and crudp

func Render ¶ added in v0.0.17

func Render(mux *http.ServeMux) error

Render registers the site handlers with the provided mux and prepares assets. DEPRECATED: Use Mount(mux) instead.

func Serve ¶ added in v0.0.17

func Serve(addr string) error

Serve starts the server on the given address (one-liner helper). It creates a new ServeMux, mounts the site, and listens on the address.

func SetAccessCheck ¶ added in v0.0.45

func SetAccessCheck(fn func(resource string, action byte, data ...any) bool)

SetAccessCheck configures an external access check function. When set, AllowedRoles() interface is NOT required on handlers. Must be called before RegisterModules().

Integration with rbac:

site.SetAccessCheck(func(resource string, action byte, data ...any) bool {
    for _, d := range data {
        if req, ok := d.(*http.Request); ok {
            userID := req.Header.Get("X-User-ID")
            ok, _ := rbac.HasPermission(userID, resource, action)
            return ok
        }
    }
    return false
})

func SetCacheSize ¶ added in v0.0.17

func SetCacheSize(size int)

SetCacheSize configures module cache size (default: 3)

func SetDefaultRoute ¶ added in v0.0.17

func SetDefaultRoute(route string)

SetDefaultRoute configures default route (default: "home")

func SetDevMode ¶ added in v0.0.17

func SetDevMode(enabled bool)

SetDevMode configures development mode (default: false)

func SetOutputDir ¶ added in v0.0.17

func SetOutputDir(dir string)

SetOutputDir configures the output directory for assets (default: "./public")

func SetUserRoles ¶ added in v0.0.16

func SetUserRoles(fn func(data ...any) []byte)

SetUserRoles configures the function to extract user roles from the request context.

Types ¶

type CSSProvider ¶ added in v0.0.45

type CSSProvider interface {
	RenderCSS() string
}

CSSProvider interface for components that provide CSS

type Config ¶ added in v0.0.5

type Config struct {
	CacheSize    int
	DefaultRoute string
	OutputDir    string
	DevMode      bool
}

type IconSvgProvider ¶ added in v0.0.45

type IconSvgProvider interface {
	IconSvg() map[string]string
}

IconSvgProvider interface for components that provide SVG icons

type JSProvider ¶ added in v0.0.45

type JSProvider interface {
	RenderJS() string
}

JSProvider interface for components that provide JS

type Module ¶ added in v0.0.17

type Module interface {
	dom.Component
	HandlerName() string
	ModuleTitle() string
}

Module represents a top-level site module. It combines a DOM component with site-specific identifiers.

type ModuleLifecycle ¶ added in v0.0.17

type ModuleLifecycle interface {
	BeforeNavigateAway() bool // Return false to cancel navigation
	AfterNavigateTo()         // Called after module is mounted
}

ModuleLifecycle provides hooks for navigation events

type Parameterized ¶ added in v0.0.17

type Parameterized interface {
	SetParams(params []string)
}

Parameterized modules can receive route parameters

Directories ¶

Path Synopsis
example
web command

Jump to

Keyboard shortcuts

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