Documentation
¶
Index ¶
- func AssignRole(userID string, roleCode byte) error
- func AutoBuild() bool
- func BuildStatic(outputDir string) error
- func CreateRole(code byte, name, description string)
- func GetUserRoleCodes(userID string) ([]byte, error)
- func Mount(mux *http.ServeMux) error
- func RegisterHandlers(handlers ...any) error
- func Render(mux *http.ServeMux) error
- func RevokeRole(userID string, roleCode byte) error
- func Serve(addr string) error
- func SetCacheSize(size int)
- func SetDB(exec DBExecutor)
- func SetDefaultRoute(route string)
- func SetDevMode(enabled bool)
- func SetOutputDir(dir string)
- func SetUserID(fn func(data ...any) string)
- func TestGetModules() []*registeredModule
- func TestIsDevMode() bool
- func TestParseRoute(hash string) (module string, params []string)
- func TestResetHandler()
- func TestSSRBuild(am *assetmin.AssetMin) error
- type Config
- type DBExecutor
- type DBRows
- type DBScanner
- type Module
- type ModuleLifecycle
- type Parameterized
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignRole ¶ added in v0.0.46
AssignRole grants a role (identified by code) to a user. Typically called in the login handler after authentication.
func AutoBuild ¶ added in v0.0.46
func AutoBuild() bool
AutoBuild checks os.Args for --ssr-static-build <dir>. If found, it runs BuildStatic and returns true so the caller should exit. Designed to be called early in main(), after RegisterHandlers.
Example usage in main.go:
site.RegisterHandlers(myModule)
if site.AutoBuild() {
return
}
func BuildStatic ¶ added in v0.0.46
BuildStatic renders all registered modules and writes the output to outputDir as static HTML/CSS/JS/SVG files using assetmin.
func CreateRole ¶ added in v0.0.46
CreateRole queues a role for creation at Serve/Mount time. Idempotent: safe to call on every startup (ON CONFLICT (code) DO NOTHING).
func GetUserRoleCodes ¶ added in v0.0.46
GetUserRoleCodes returns the role codes assigned to a user (e.g., []byte{'a', 'e'}).
func Mount ¶ added in v0.0.5
Mount registers the site handlers with the provided mux and prepares assets.
func RegisterHandlers ¶
RegisterHandlers registers all handlers with site and crudp
func Render ¶ added in v0.0.17
Render registers the site handlers with the provided mux and prepares assets. DEPRECATED: Use Mount(mux) instead.
func RevokeRole ¶ added in v0.0.46
RevokeRole removes a role (identified by code) from a user.
func Serve ¶ added in v0.0.17
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 SetCacheSize ¶ added in v0.0.17
func SetCacheSize(size int)
SetCacheSize configures module cache size (default: 3)
func SetDB ¶ added in v0.0.46
func SetDB(exec DBExecutor)
SetDB sets the database executor. rbac initialization is deferred to Serve/Mount.
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 SetUserID ¶ added in v0.0.46
SetUserID configures how to extract the current user's ID from request data. Required when SetDB has been called. Validated at Mount time.
func TestGetModules ¶ added in v0.0.46
func TestGetModules() []*registeredModule
TestGetModules returns the list of registered modules. For testing purposes only.
func TestIsDevMode ¶ added in v0.0.46
func TestIsDevMode() bool
TestIsDevMode returns the current DevMode state of the handler. For testing purposes only.
func TestParseRoute ¶ added in v0.0.46
TestParseRoute exposes the internal parseRoute function for testing. For testing purposes only.
func TestResetHandler ¶ added in v0.0.46
func TestResetHandler()
TestResetHandler resets the global handler state for testing. For testing purposes only.
func TestSSRBuild ¶ added in v0.0.46
TestSSRBuild exposes the internal ssrBuild function for testing. For testing purposes only.
Types ¶
type Config ¶ added in v0.0.5
func TestGetConfig ¶ added in v0.0.46
func TestGetConfig() *Config
TestGetConfig returns the global configuration. For testing purposes only.
type DBExecutor ¶ added in v0.0.46
Type aliases — callers don't need to import tinywasm/rbac directly.
type Module ¶ added in v0.0.17
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 {
}
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