helpers

package
v2.17.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 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 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

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 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 CacheConfig struct {
	RedisURL          string
	RedisPassword     string
	RedisTLS          bool
	CacheFilesPath    string
	Compression       bool
	CompressionMethod CompressionMethod
}

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 int
const (
	CACHE_CONTROL_HEADERS CacheType = iota // Default — production behavior (Cache-Control headers for CDN)
	IN_MEMORY                              // Go in-memory map
	REDIS                                  // Redis-backed
	LOCAL_FILES                            // File-system-backed
)

type CompressionMethod

type CompressionMethod int
const (
	GZIP   CompressionMethod = iota // Default compression method
	BROTLI                          // Brotli compression
)

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
	// 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 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
)

Jump to

Keyboard shortcuts

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