Documentation
¶
Index ¶
- Constants
- Variables
- func InitCache(cacheType CacheType, config *CacheConfig)
- func SetEmbeddedPublicFS(fsys fs.FS)
- func Setup(router chi.Router, config AppConfig, registerRoutes func(chi.Router))
- 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 ¶
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 SetEmbeddedPublicFS ¶ added in v1.5.0
SetEmbeddedPublicFS registers the embed.FS backing /public/* when ServeStaticFiles == EMBEDDED. fsys MUST already be rooted at the public dir (fs.Sub'd) so its top-level entries are the files inside public/. The generated root embed file calls this from init(), before main().
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 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 = config.RuntimeConfig
The routing/caching config types and enums are defined canonically in the lightweight, user-facing pkg/config package (so a project can write them as gothic.* in gothic.config.go). They are re-exported here as aliases so the rest of this package — and existing user code — keeps using the gothicRoutes.* names unchanged, while there is exactly one definition.
type CacheConfig ¶
type CacheConfig = config.CacheConfig
The routing/caching config types and enums are defined canonically in the lightweight, user-facing pkg/config package (so a project can write them as gothic.* in gothic.config.go). They are re-exported here as aliases so the rest of this package — and existing user code — keeps using the gothicRoutes.* names unchanged, while there is exactly one definition.
type CacheStore ¶
type CacheType ¶
The routing/caching config types and enums are defined canonically in the lightweight, user-facing pkg/config package (so a project can write them as gothic.* in gothic.config.go). They are re-exported here as aliases so the rest of this package — and existing user code — keeps using the gothicRoutes.* names unchanged, while there is exactly one definition.
type CompressionMethod ¶
type CompressionMethod = config.CompressionMethod
The routing/caching config types and enums are defined canonically in the lightweight, user-facing pkg/config package (so a project can write them as gothic.* in gothic.config.go). They are re-exported here as aliases so the rest of this package — and existing user code — keeps using the gothicRoutes.* names unchanged, while there is exactly one definition.
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 // Multiplexed, when true, makes every placement of this component type on a // page share ONE WASM instance via scope register/unregister instead of // instantiating the binary once per placement. Opt-in and additive: the // default (false) path is byte-identical to the per-placement behavior. // Collapses the N-per-row leak case (N per-row WASM instances → 1 instance). // Topic managers are never multiplexed. Multiplexed bool // 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 = config.StaticFilesMode
The routing/caching config types and enums are defined canonically in the lightweight, user-facing pkg/config package (so a project can write them as gothic.* in gothic.config.go). They are re-exported here as aliases so the rest of this package — and existing user code — keeps using the gothicRoutes.* names unchanged, while there is exactly one definition.
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 )