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
- type App
- func (a *App) Broadcast(message []byte)
- func (a *App) BroadcastState(key string, value interface{}) error
- 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) GetRouter() *routing.Router
- func (a *App) Group(prefix string, handlers ...fiberpkg.Handler) fiberpkg.Router
- 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) Use(middleware ...fiberpkg.Handler)
- type Config
- type StateDeserializerFunc
- type StateSerializerFunc
Constants ¶
View Source
const Version = "0.1.7"
Version is the current version of GoSPA.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 WebSocket clients.
func (*App) RegisterRoutes ¶
RegisterRoutes registers all scanned routes with Fiber.
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
// Performance Options
// CompressState enables gzip compression of outbound WebSocket state payloads.
// The client receives a { type:"compressed", data: "<base64>", compressed: true }
// envelope and must decompress using the DecompressionStream browser API.
CompressState bool
// StateDiffing enables delta-only "patch" WebSocket messages for state syncs.
// Only changed state keys are transmitted after the initial full snapshot.
StateDiffing bool
CacheTemplates bool // Cache compiled templates (SSG only)
SimpleRuntime bool // Use lightweight runtime without DOMPurify (~6KB smaller)
// SimpleRuntimeSVGs allows SVG elements in the simple runtime sanitizer.
// WARNING: Only enable if your content is fully trusted and never user-generated.
SimpleRuntimeSVGs bool
// WebSocket Options — these values are passed directly to the client runtime's init() call.
// Defaults: WSReconnectDelay=1s, WSMaxReconnect=10, WSHeartbeat=30s.
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 0.2).
WSConnRateLimit float64
// WSConnBurst sets the burst capacity for WebSocket connection upgrades (default 5.0).
WSConnBurst float64
// Hydration Options
// HydrationMode controls when components become interactive.
// Supported values: "immediate" | "lazy" | "visible" | "idle" (default: "immediate").
HydrationMode string
HydrationTimeout int // ms before force hydrate (used with "visible" and "idle" modes)
// Serialization Options
// StateSerializer overrides JSON for outbound WebSocket state serialization.
// StateDeserializer overrides JSON for inbound WebSocket state deserialization.
StateSerializer StateSerializerFunc
StateDeserializer StateDeserializerFunc
// Routing Options
DisableSPA bool // Disable SPA navigation completely
// NOTE: SSR (global SSR mode) is planned but not yet implemented — currently all pages are SSR by default.
SSR bool
// Rendering Strategy Defaults
// DefaultRenderStrategy sets the fallback strategy for pages that do not
// explicitly call RegisterPageWithOptions. Defaults to StrategySSR.
DefaultRenderStrategy routing.RenderStrategy
// DefaultRevalidateAfter is the ISR TTL used when a page uses StrategyISR
// but does not set RouteOptions.RevalidateAfter. Zero means revalidate every request.
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")
// Security Options
AllowedOrigins []string // Allowed CORS origins
EnableCSRF bool // Enable automatic CSRF protection (requires CSRFSetTokenMiddleware + CSRFTokenMiddleware)
// SSGCacheMaxEntries caps the SSG/ISR/PPR page cache size. Oldest entries are evicted when full.
// Default: 500. Set to -1 to disable eviction (unbounded, not recommended in production).
SSGCacheMaxEntries int
// SSGCacheTTL sets an expiration time for SSG cache entries. If zero, they never expire.
SSGCacheTTL time.Duration
// Prefork enables Fiber's prefork mode.
// WARNING: If enabled without an external Storage/PubSub backend like Redis, in-memory state and WebSockets will be isolated per-process.
Prefork bool
// Storage defines the external storage backend for sessions and state. Defaults to in-memory.
Storage store.Storage
// PubSub defines the messaging backend for multi-process broadcasting. Defaults to in-memory.
PubSub store.PubSub
// IgnoredExtensions is a list of file extensions that the SPA router should ignore.
// If nil, a default list of common non-HTML extensions is used.
IgnoredExtensions []string
// AppendIgnoredExtensions is a list of file extensions to add to the default list.
AppendIgnoredExtensions []string
}
Config holds the application configuration.
type StateDeserializerFunc ¶
StateDeserializerFunc defines a function for state deserialization
type StateSerializerFunc ¶
StateSerializerFunc defines a function for state serialization
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 tool.
|
Package main provides the gospa CLI tool. |
|
gospa-gen
command
Package main provides a code generator for GoSPA route registration.
|
Package main provides a code generator for GoSPA route registration. |
|
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. |
|
Package fiber provides error overlay functionality for development.
|
Package fiber provides error overlay functionality for development. |
|
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. |
|
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. |
|
Package state provides batch update support for reactive primitives.
|
Package state provides batch update support for reactive primitives. |
|
Package templ provides Templ integration helpers for GoSPA reactive bindings.
|
Package templ provides Templ integration helpers for GoSPA reactive bindings. |
|
website
module
|
Click to show internal directories.
Click to hide internal directories.