helpers

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CACHE_CONTROL_HEADERS = config.CACHE_CONTROL_HEADERS
	IN_MEMORY             = config.IN_MEMORY
	REDIS                 = config.REDIS
	LOCAL_FILES           = config.LOCAL_FILES

	CDN      = config.CDN
	DISK     = config.DISK
	EMBEDDED = config.EMBEDDED

	GZIP   = config.GZIP
	BROTLI = config.BROTLI
)

Variables

View Source
var DefaultApiConfig = ApiRouteConfig{
	HttpMethod: GET,
	Type:       DYNAMIC,
}
View Source
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

func SetEmbeddedPublicFS(fsys fs.FS)

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

func Setup(router chi.Router, config AppConfig, registerRoutes func(chi.Router))

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

func WasmOutputName(httpPath string) string

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 CacheStore interface {
	Get(key string) ([]byte, bool)
	Set(key string, value []byte, ttl time.Duration)
	Flush() error
	Close() error
}

type CacheType

type CacheType = config.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 ConfigType

type ConfigType int
const (
	ISR ConfigType = iota
	STATIC
	DYNAMIC
)

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 HttpMethod

type HttpMethod int
const (
	GET HttpMethod = iota
	POST
	PUT
	PATCH
	DELETE
)

type Imports

type Imports struct {
	Package     string
	PackagePath string
}

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

func (*InMemoryCacheStore) Get

func (s *InMemoryCacheStore) Get(key string) ([]byte, bool)

func (*InMemoryCacheStore) Set

func (s *InMemoryCacheStore) Set(key string, value []byte, ttl time.Duration)

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

func (*LocalFilesCacheStore) Get

func (s *LocalFilesCacheStore) Get(key string) ([]byte, bool)

func (*LocalFilesCacheStore) Set

func (s *LocalFilesCacheStore) Set(key string, value []byte, ttl time.Duration)

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

func (*RedisCacheStore) Get

func (s *RedisCacheStore) Get(key string) ([]byte, bool)

func (*RedisCacheStore) Set

func (s *RedisCacheStore) Set(key string, value []byte, ttl time.Duration)

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 (config *RouteConfig[T]) RegisterRoute(r chi.Router, httpPath string, component func(T) templ.Component)

func (*RouteConfig[T]) Render

func (config *RouteConfig[T]) Render(r *http.Request, w http.ResponseWriter, component templ.Component) error

type RouteTemplate

type RouteTemplate struct {
	FunctionName      string
	ConfigName        string
	PackageName       string
	ConfigPackageName string
	HttpPath          string
	OriginFile        string
}

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL