Documentation
¶
Overview ¶
Package gospa provides a modern SPA framework for Go with Fiber and Templ. It brings Svelte-like reactivity and state management to Go.
Index ¶
- Constants
- Variables
- func Broadcast(message interface{}) error
- type App
- func (a *App) Broadcast(message []byte)
- func (a *App) BroadcastState(key string, value interface{}) error
- func (a *App) Computed(key string, deps []string, fn func(map[string]interface{}) interface{}) *App
- func (a *App) Context() context.Context
- func (a *App) Delete(path string, handlers ...fiberpkg.Handler)
- func (a *App) Get(path string, handlers ...fiberpkg.Handler)
- func (a *App) GetFiber() *fiberpkg.App
- func (a *App) GetHub() *fiber.WSHub
- func (a *App) GetPlugin(name string) (plugin.Plugin, bool)
- func (a *App) GetRouter() *routing.Router
- func (a *App) GetTemplateFuncs() map[string]any
- func (a *App) Group(prefix string, handlers ...fiberpkg.Handler) fiberpkg.Router
- func (a *App) Invalidate(path string) int
- func (a *App) InvalidateAll() int
- func (a *App) InvalidateKey(key string) int
- func (a *App) InvalidateTag(tag string) int
- func (a *App) ListPlugins() []plugin.Info
- func (a *App) Logger() *slog.Logger
- func (a *App) Post(path string, handlers ...fiberpkg.Handler)
- func (a *App) Put(path string, handlers ...fiberpkg.Handler)
- func (a *App) RegisterRoutes() error
- func (a *App) Run(addr string) error
- func (a *App) RunTLS(addr, certFile, keyFile string) error
- func (a *App) Scan() error
- func (a *App) Shutdown() error
- func (a *App) Static(prefix, root string)
- func (a *App) UsePlugin(p plugin.Plugin) error
- func (a *App) UsePlugins(plugins ...plugin.Plugin) error
- type Config
- type ConfigOption
- func WithAppName(name string) ConfigOption
- func WithCacheTemplates(enabled bool) ConfigOption
- func WithDevMode(enabled bool) ConfigOption
- func WithLogger(logger *slog.Logger) ConfigOption
- func WithPort(_ string) ConfigOption
- func WithRoutesDir(dir string) ConfigOption
- func WithStaticDir(dir string) ConfigOption
- func WithStaticPrefix(prefix string) ConfigOption
- func WithWebSocket(enabled bool) ConfigOption
- func WithWebSocketPath(path string) ConfigOption
- type NavigationIdleCallbackBatchUpdatesConfig
- type NavigationLazyRuntimeInitializationConfig
- type NavigationOptions
- type NavigationProgressBarConfig
- type NavigationServiceWorkerCachingConfig
- type NavigationSpeculativePrefetchingConfig
- type NavigationURLParsingCacheConfig
- type NavigationViewTransitionsConfig
- type StateDeserializerFunc
- type StateSerializerFunc
Constants ¶
const ( // SerializationJSON uses standard JSON for state. SerializationJSON = "json" // SerializationMsgPack uses MessagePack for more compact state. SerializationMsgPack = "msgpack" )
Serialization format constants.
const ( RuntimeTierMicro = compiler.RuntimeTierMicro RuntimeTierCore = compiler.RuntimeTierCore RuntimeTierFull = compiler.RuntimeTierFull )
RuntimeTier constants (pointing to compiler package)
const Version = "0.1.41"
Version is the current version of GoSPA.
Variables ¶
var ErrJSONTooDeep = errors.New("json nesting exceeds maximum")
ErrJSONTooDeep is returned when remote action JSON exceeds [remoteJSONMaxNesting].
Functions ¶
Types ¶
type App ¶
type App struct {
// Config is the application configuration.
Config Config
// Router is the file-based router.
Router *routing.Router
// Fiber is the underlying Fiber app.
Fiber *fiberpkg.App
// Hub is the WebSocket hub for real-time updates.
Hub *fiber.WSHub
// StateMap is the global state map.
StateMap *state.StateMap
// contains filtered or unexported fields
}
App is the main GoSPA application.
func (*App) BroadcastState ¶
BroadcastState broadcasts a state update to all connected clients.
func (*App) Computed ¶ added in v0.1.32
Computed adds a computed state variable to the application's global state. It automatically updates when its dependencies change and broadcasts the result to all clients.
func (*App) GetTemplateFuncs ¶ added in v0.1.29
GetTemplateFuncs returns template functions registered by plugins.
func (*App) Group ¶
Group creates a new route group with the specified prefix and optional handlers.
func (*App) Invalidate ¶ added in v0.1.38
Invalidate removes cache entries associated with the provided route path.
func (*App) InvalidateAll ¶ added in v0.1.41
InvalidateAll removes all in-memory route caches and clears index mappings. Returns number of entries removed across SSG and PPR caches.
func (*App) InvalidateKey ¶ added in v0.1.38
InvalidateKey removes all cache entries indexed under the provided key.
func (*App) InvalidateTag ¶ added in v0.1.38
InvalidateTag removes all cache entries indexed under the provided tag.
func (*App) ListPlugins ¶ added in v0.1.29
ListPlugins returns information about all registered plugins.
func (*App) RegisterRoutes ¶
RegisterRoutes manually triggers route registration.
type Config ¶
type Config struct {
// RoutesDir is the directory containing route files.
RoutesDir string
// RoutesFS is the filesystem containing route files (optional). Takes precedence over RoutesDir if provided.
RoutesFS fs.FS
// DevMode enables development features.
DevMode bool
// RuntimeScript is the path to the client runtime script.
RuntimeScript string
// StaticDir is the directory for static files.
StaticDir string
// StaticPrefix is the URL prefix for static files.
StaticPrefix string
// AppName is the application name.
AppName string
// DefaultState is the initial state for new sessions.
DefaultState map[string]interface{}
// EnableWebSocket enables WebSocket support.
EnableWebSocket bool
// WebSocketPath is the WebSocket endpoint path.
WebSocketPath string
// WebSocketMiddleware allows injecting session/auth middleware before WebSocket upgrade.
WebSocketMiddleware fiberpkg.Handler
// Logger is the structured logger. Defaults to slog.Default().
Logger *slog.Logger
// Performance Options
// CompressState enables gzip compression of outbound WebSocket state payloads.
CompressState bool
// StateDiffing enables delta-only "patch" WebSocket messages for state syncs.
StateDiffing bool
CacheTemplates bool // Cache compiled templates (SSG only)
// RuntimeTier specifies the complexity of the client runtime.
RuntimeTier compiler.RuntimeTier
// SimpleRuntimeSVGs allows SVG elements in the simple runtime sanitizer.
SimpleRuntimeSVGs bool
// DisableSanitization disables client-side HTML sanitization for SPA navigation.
DisableSanitization bool
// NotificationBufferSize sets the size of the state change notification queue (default 1024).
NotificationBufferSize int
// WebSocket Options — these values are passed directly to the client runtime's init() call.
WSReconnectDelay time.Duration // Initial reconnect delay (default 1s)
WSMaxReconnect int // Max reconnect attempts (default 10)
WSHeartbeat time.Duration // Heartbeat ping interval (default 30s)
// WSMaxMessageSize limits the maximum payload size for WebSocket messages (default 64KB).
WSMaxMessageSize int
// WSConnRateLimit sets the refilling rate in connections per second for WebSocket upgrades (default 1.5).
WSConnRateLimit float64
// WSConnBurst sets the burst capacity for WebSocket connection upgrades (default 15.0).
WSConnBurst float64
// Hydration Options
HydrationMode string
HydrationTimeout int // ms before force hydrate
// Serialization Options
SerializationFormat string
StateSerializer StateSerializerFunc
StateDeserializer StateDeserializerFunc
// Routing Options
DisableSPA bool // Disable SPA navigation completely
// Rendering Strategy Defaults
DefaultRenderStrategy routing.RenderStrategy
DefaultRevalidateAfter time.Duration
// Remote Action Options
MaxRequestBodySize int // Maximum allowed size for remote action request bodies
RemotePrefix string // Prefix for remote action endpoints (default "/_gospa/remote")
RemoteActionMiddleware fiberpkg.Handler // Optional middleware
AllowUnauthenticatedRemoteActions bool // Default false
// Security Options
AllowedOrigins []string
EnableCSRF bool
ContentSecurityPolicy string
PublicOrigin string
// StrictProduction enforces hard startup validation for production deployments.
StrictProduction bool
// AllowInsecureWS allows unsecure ws:// connections even on https:// pages.
// This is useful for development setups with reverse proxies that don't support wss://.
AllowInsecureWS bool
// AllowPortsWithInsecureWS allows unsecure ws:// connections for these specific ports, even on https:// pages.
// This is useful for development setups with reverse proxies that don't support wss://.
// Defaults to []int{3000}.
AllowPortsWithInsecureWS []int
SSGCacheMaxEntries int // Default: 500
SSGCacheTTL time.Duration // Default: 0 (no expiry)
// Prefork enables Fiber's prefork mode.
Prefork bool
// Storage defines the external storage backend for sessions and state.
Storage store.Storage
// PubSub defines the messaging backend for multi-process broadcasting.
PubSub store.PubSub
NavigationOptions NavigationOptions
// ISR Options
// ISRSemaphoreLimit limits concurrent ISR background revalidations.
ISRSemaphoreLimit int
// ISRTimeout sets the maximum time for a background ISR revalidation.
ISRTimeout time.Duration
// IslandsBundlePath is the path to the islands bundle script.
IslandsBundlePath string
// PreloadCSS contains paths to CSS files that should be preloaded with high priority.
PreloadCSS []string
// BuildManifest is the loaded manifest.json (optional).
BuildManifest map[string]string
// ManifestPath is the path to manifest.json (default: "./manifest.json").
ManifestPath string
}
Config holds the application configuration.
func MinimalConfig ¶ added in v0.1.30
func MinimalConfig() Config
MinimalConfig returns a smaller baseline.
func ProductionConfig ¶ added in v0.1.30
func ProductionConfig() Config
ProductionConfig returns an opinionated production-ready baseline.
func StrictProductionConfig ¶ added in v0.1.39
func StrictProductionConfig() Config
StrictProductionConfig returns a hardened production baseline that fails fast on missing security and runtime safety settings.
type ConfigOption ¶ added in v0.1.33
type ConfigOption func(*Config)
ConfigOption is a functional option for configuring the app.
func WithAppName ¶ added in v0.1.33
func WithAppName(name string) ConfigOption
WithAppName sets the application name.
func WithCacheTemplates ¶ added in v0.1.33
func WithCacheTemplates(enabled bool) ConfigOption
WithCacheTemplates enables template caching for SSG/ISR.
func WithDevMode ¶ added in v0.1.33
func WithDevMode(enabled bool) ConfigOption
WithDevMode enables development mode.
func WithLogger ¶ added in v0.1.33
func WithLogger(logger *slog.Logger) ConfigOption
WithLogger sets the logger.
func WithPort ¶ added in v0.1.33
func WithPort(_ string) ConfigOption
WithPort sets the server port. Note: This option is a no-op for the App; the port is passed directly to app.Run(addr) instead.
func WithRoutesDir ¶ added in v0.1.33
func WithRoutesDir(dir string) ConfigOption
WithRoutesDir sets the routes directory.
func WithStaticDir ¶ added in v0.1.33
func WithStaticDir(dir string) ConfigOption
WithStaticDir sets the static files directory.
func WithStaticPrefix ¶ added in v0.1.33
func WithStaticPrefix(prefix string) ConfigOption
WithStaticPrefix sets the URL prefix for static files.
func WithWebSocket ¶ added in v0.1.33
func WithWebSocket(enabled bool) ConfigOption
WithWebSocket enables or disables WebSocket support.
func WithWebSocketPath ¶ added in v0.1.33
func WithWebSocketPath(path string) ConfigOption
WithWebSocketPath sets the WebSocket endpoint path.
type NavigationIdleCallbackBatchUpdatesConfig ¶ added in v0.1.22
type NavigationIdleCallbackBatchUpdatesConfig struct {
}
NavigationIdleCallbackBatchUpdatesConfig configures idle callback batching
type NavigationLazyRuntimeInitializationConfig ¶ added in v0.1.22
type NavigationLazyRuntimeInitializationConfig struct {
}
NavigationLazyRuntimeInitializationConfig configures lazy runtime init
type NavigationOptions ¶ added in v0.1.22
type NavigationOptions struct {
}
NavigationOptions configures client-side navigation
type NavigationProgressBarConfig ¶ added in v0.1.30
type NavigationProgressBarConfig struct {
}
NavigationProgressBarConfig configures the navigation progress bar
type NavigationServiceWorkerCachingConfig ¶ added in v0.1.22
type NavigationServiceWorkerCachingConfig struct {
}
NavigationServiceWorkerCachingConfig configures service worker caching
type NavigationSpeculativePrefetchingConfig ¶ added in v0.1.22
type NavigationSpeculativePrefetchingConfig struct {
}
NavigationSpeculativePrefetchingConfig configures speculative prefetching
type NavigationURLParsingCacheConfig ¶ added in v0.1.22
type NavigationURLParsingCacheConfig struct {
}
NavigationURLParsingCacheConfig configures the URL parsing cache
type NavigationViewTransitionsConfig ¶ added in v0.1.22
type NavigationViewTransitionsConfig struct {
}
NavigationViewTransitionsConfig configures view transitions
type StateDeserializerFunc ¶
StateDeserializerFunc defines a function for state deserialization
type StateSerializerFunc ¶
StateSerializerFunc defines a function for state serialization
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cli provides command-line interface tools for GoSPA.
|
Package cli provides command-line interface tools for GoSPA. |
|
cmd
|
|
|
gospa
command
Package main provides the GoSPA CLI entry point.
|
Package main provides the GoSPA CLI entry point. |
|
gospa-gen
command
Package main provides a code generator for GoSPA route registration.
|
Package main provides a code generator for GoSPA route registration. |
|
gospa-lsp
command
Package main implements the GoSPA Language Server Protocol.
|
Package main implements the GoSPA Language Server Protocol. |
|
Package compiler provides a compiler for GoSPA Single File Components (.gospa).
|
Package compiler provides a compiler for GoSPA Single File Components (.gospa). |
|
sfc
Package sfc provides a parser for GoSPA Single File Components (.gospa).
|
Package sfc provides a parser for GoSPA Single File Components (.gospa). |
|
Package component provides island architecture support for GoSPA.
|
Package component provides island architecture support for GoSPA. |
|
starter
Package starter provides a library of reusable UI components for GoSPA applications
|
Package starter provides a library of reusable UI components for GoSPA applications |
|
Package embed provides embedded static assets for the GoSPA framework.
|
Package embed provides embedded static assets for the GoSPA framework. |
|
examples
|
|
|
counter-test-prefork
module
|
|
|
form-remote
module
|
|
|
Package fiber provides error overlay functionality for development.
|
Package fiber provides error overlay functionality for development. |
|
Package plugin provides external plugin loading capabilities for GoSPA.
|
Package plugin provides external plugin loading capabilities for GoSPA. |
|
auth
Package auth provides authentication for GoSPA projects.
|
Package auth provides authentication for GoSPA projects. |
|
image
Package image provides image optimization for GoSPA projects.
|
Package image provides image optimization for GoSPA projects. |
|
pathsafety
Package pathsafety provides safe path resolution helpers.
|
Package pathsafety provides safe path resolution helpers. |
|
postcss
Package postcss provides a PostCSS plugin for GoSPA with Tailwind CSS v4 support.
|
Package postcss provides a PostCSS plugin for GoSPA with Tailwind CSS v4 support. |
|
qrcode
Package qrcode provides QR code generation for GoSPA applications.
|
Package qrcode provides QR code generation for GoSPA applications. |
|
seo
Package seo provides SEO optimization for GoSPA projects.
|
Package seo provides SEO optimization for GoSPA projects. |
|
tailwind
Package tailwind provides a Tailwind CSS v4 plugin for GoSPA.
|
Package tailwind provides a Tailwind CSS v4 plugin for GoSPA. |
|
validation
Package validation provides form validation for GoSPA projects.
|
Package validation provides form validation for GoSPA projects. |
|
Package routing provides file-based routing similar to SvelteKit.
|
Package routing provides file-based routing similar to SvelteKit. |
|
generator
Package generator provides code generation for automatic route registration.
|
Package generator provides code generation for automatic route registration. |
|
kit
Package kit provides control-flow helpers for route load/action handlers.
|
Package kit provides control-flow helpers for route load/action handlers. |
|
scripts
|
|
|
check-docs-sync
command
Package main provides a script to audit documentation consistency between website routes and authoritative markdown files.
|
Package main provides a script to audit documentation consistency between website routes and authoritative markdown files. |
|
codemod-sfc-events
command
Package main rewrites legacy SFC event attribute syntaxes to `on:<event>=`.
|
Package main rewrites legacy SFC event attribute syntaxes to `on:<event>=`. |
|
fix-docs-links
command
Package main provides a script to fix legacy documentation links in markdown files.
|
Package main provides a script to fix legacy documentation links in markdown files. |
|
tag
command
Package main provides a script to bump version and create a new git tag.
|
Package main provides a script to bump version and create a new git tag. |
|
validate-docs-routes
command
Package main validates docs route and search index integrity.
|
Package main validates docs route and search index integrity. |
|
validate-helper-promotion
command
Package main validates that promoted helper APIs have docs, migration mapping, and tests references.
|
Package main validates that promoted helper APIs have docs, migration mapping, and tests references. |
|
Package state provides batch update support for reactive primitives.
|
Package state provides batch update support for reactive primitives. |
|
Package store provides pubsub state backends for GoSPA.
|
Package store provides pubsub state backends for GoSPA. |
|
redis
Package redis provides a Redis-backed implementation of the store.Storage interface.
|
Package redis provides a Redis-backed implementation of the store.Storage interface. |
|
Package templ provides Templ integration helpers for GoSPA reactive bindings.
|
Package templ provides Templ integration helpers for GoSPA reactive bindings. |
|
Package main is the benchmark tool for GoSPA.
|
Package main is the benchmark tool for GoSPA. |
|
website
module
|