Documentation
¶
Index ¶
- Variables
- func InitCache(cacheType CacheType, config *CacheConfig)
- func Setup(router chi.Router, config AppConfig, registerRoutes func(chi.Router))
- func TopicManagerComponent(wasmName string, compression CompressionMethod) templ.Component
- func WasmOutputName(httpPath string) string
- type ApiRouteConfig
- type AppConfig
- type CacheConfig
- type CacheStore
- type CacheType
- type CompressionMethod
- type ConfigType
- type FileBasedRouteHelper
- type HttpMethod
- type Imports
- type InMemoryCacheStore
- type LocalFilesCacheStore
- type RedisCacheStore
- type RouteConfig
- type RouteTemplate
- type StaticFilesMode
- type TemplateInfo
- type WasmCompiler
Constants ¶
This section is empty.
Variables ¶
var DefaultApiConfig = ApiRouteConfig{ HttpMethod: GET, Type: DYNAMIC, }
var DefaultConfig = RouteConfig[any]{ Type: STATIC, HttpMethod: GET, Middleware: func(w http.ResponseWriter, r *http.Request) any { return nil }, }
Functions ¶
func InitCache ¶
func InitCache(cacheType CacheType, config *CacheConfig)
InitCache explicitly initializes the global cache store with the given type and config. This should be called from the server entry point before routes are registered. If called multiple times, only the first call takes effect.
func Setup ¶
Setup initializes caching, static file serving, and registers routes. It reads the GOTHIC_MODE environment variable to determine dev vs production mode. In dev mode (GOTHIC_MODE=dev), LocalDevelopmentCache is used; in production, CacheStrategy is used.
func TopicManagerComponent ¶
func TopicManagerComponent(wasmName string, compression CompressionMethod) templ.Component
TopicManagerComponent returns a templ.Component that loads the named topic-manager WASM inline (no HTMX round-trip). Drop it in any layout or page with @wasm.AddPageTopic().
func WasmOutputName ¶
WasmOutputName converts an HTTP path to a safe filename for public/wasm/.
/ → index
/counter → counter
/user/{id} → user-id
/blog/{slug}/comments → blog-slug-comments
Types ¶
type ApiRouteConfig ¶
type ApiRouteConfig struct {
Type ConfigType
HttpMethod HttpMethod
RevalidateInSec int
}
func (*ApiRouteConfig) RegisterRoute ¶
func (config *ApiRouteConfig) RegisterRoute(r chi.Router, httpPath string, fn func(w http.ResponseWriter, r *http.Request))
type AppConfig ¶
type AppConfig struct {
// CacheStrategy selects the production cache backend.
CacheStrategy CacheType
// LocalDevelopmentCache selects the dev cache backend. Default: IN_MEMORY.
LocalDevelopmentCache CacheType
// ServeStaticFiles controls when /public/* is served from disk.
// HOT_RELOAD_ONLY (default): only during development.
// ALL_ENVS: all environments (public folder must be present alongside the binary).
ServeStaticFiles StaticFilesMode
// CacheConfig provides backend-specific settings (Redis URL, file path, compression).
CacheConfig *CacheConfig
}
type CacheConfig ¶
type CacheStore ¶
type CompressionMethod ¶
type CompressionMethod int
const ( GZIP CompressionMethod = iota // Default compression method BROTLI // Brotli compression )
type FileBasedRouteHelper ¶
type FileBasedRouteHelper struct {
TemplateInfo TemplateInfo
OutputFile string
TemplateFile string
ApiRoutesFolder string
ComponentRoutesFolder string
PageRoutesFolder string
Template helpers.TemplateHelper
}
func NewFileBasedRouteHelper ¶
func NewFileBasedRouteHelper() FileBasedRouteHelper
func (*FileBasedRouteHelper) Initialize ¶
func (helper *FileBasedRouteHelper) Initialize(goModName string)
func (*FileBasedRouteHelper) RemoveDuplicates ¶
func (helper *FileBasedRouteHelper) RemoveDuplicates()
func (*FileBasedRouteHelper) Render ¶
func (helper *FileBasedRouteHelper) Render(goModName string) error
type InMemoryCacheStore ¶
type InMemoryCacheStore struct {
// contains filtered or unexported fields
}
func NewInMemoryCacheStore ¶
func NewInMemoryCacheStore(config *CacheConfig) *InMemoryCacheStore
func (*InMemoryCacheStore) Close ¶
func (s *InMemoryCacheStore) Close() error
func (*InMemoryCacheStore) Flush ¶
func (s *InMemoryCacheStore) Flush() error
type LocalFilesCacheStore ¶
type LocalFilesCacheStore struct {
// contains filtered or unexported fields
}
func NewLocalFilesCacheStore ¶
func NewLocalFilesCacheStore(config *CacheConfig) (*LocalFilesCacheStore, error)
func (*LocalFilesCacheStore) Close ¶
func (s *LocalFilesCacheStore) Close() error
func (*LocalFilesCacheStore) Flush ¶
func (s *LocalFilesCacheStore) Flush() error
type RedisCacheStore ¶
type RedisCacheStore struct {
// contains filtered or unexported fields
}
func NewRedisCacheStore ¶
func NewRedisCacheStore(config *CacheConfig) (*RedisCacheStore, error)
func (*RedisCacheStore) Close ¶
func (s *RedisCacheStore) Close() error
func (*RedisCacheStore) Flush ¶
func (s *RedisCacheStore) Flush() error
type RouteConfig ¶
type RouteConfig[T any] struct { Type ConfigType HttpMethod HttpMethod RevalidateInSec int Middleware func(w http.ResponseWriter, r *http.Request) T // ClientSideState, if non-nil, marks this route as having a WASM reactive state // function. The CLI extracts the function body and compiles it with TinyGo. // The function is never called server-side; it only needs to compile. ClientSideState func() // WasmCompression sets the compression algorithm for the compiled WASM output. // Defaults to GZIP (zero value). Options: GZIP, BROTLI. WasmCompression CompressionMethod // WasmCompiler selects the WASM build toolchain. Defaults to GothicTinyGo. WasmCompiler WasmCompiler // Path is the HTTP route path, set automatically by RegisterRoute. // Use it with StatefulComponentOf to avoid hardcoding path strings. Path string }
func (*RouteConfig[T]) RegisterRoute ¶
func (*RouteConfig[T]) Render ¶
func (config *RouteConfig[T]) Render(r *http.Request, w http.ResponseWriter, component templ.Component) error
type RouteTemplate ¶
type StaticFilesMode ¶
type StaticFilesMode int
const ( HOT_RELOAD_ONLY StaticFilesMode = iota // Serve /public/* only during development ALL_ENVS // Serve /public/* in all environments (requires public folder at runtime) )
type TemplateInfo ¶
type TemplateInfo struct {
GoModName string
ImportDefault bool
Imports []Imports
Routes []RouteTemplate
ApiRoutes []RouteTemplate
}
type WasmCompiler ¶
type WasmCompiler int
WasmCompiler selects the WASM build toolchain for a route.
const ( GothicTinyGo WasmCompiler = iota // default: embedded TinyGo binary LocalTinyGo // system tinygo binary in PATH Golang // GOOS=js GOARCH=wasm standard Go compiler )