handlers

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncComponentResponse added in v0.4.1

type AsyncComponentResponse struct {
	Success      bool                     `json:"success"`
	Component    string                   `json:"component"`
	ClassName    string                   `json:"className"`
	JS           string                   `json:"js"`
	CSS          string                   `json:"css"`
	Dependencies []AsyncComponentResponse `json:"dependencies,omitempty"`
	Error        string                   `json:"error,omitempty"`
}

type CachedModule added in v0.3.0

type CachedModule struct {
	Exports      *js.Object
	LastModified time.Time
}

CachedModule represents a cached JavaScript module

type CachedResult added in v0.4.0

type CachedResult struct {
	HTML         string
	ContentHash  string   // MD5 hash of the source content
	ConfigHash   string   // Hash of config for cache invalidation
	Dependencies []string // List of component dependencies
}

type ComponentHandler added in v0.5.0

type ComponentHandler interface {
	// CanHandle determines if this handler can process the given request path
	CanHandle(requestPath string) bool
	// ServeComponent handles the component request
	ServeComponent(w http.ResponseWriter, r *http.Request)
}

ComponentHandler defines the interface for handling component requests

type ComponentInfo added in v0.4.1

type ComponentInfo struct {
	FilePath     string    // Path to the component file
	Name         string    // Component name (e.g., "Button")
	ClassName    string    // Class name (e.g., "Button")
	CompiledJS   string    // Compiled JavaScript code
	CompiledCSS  string    // Compiled CSS code
	Dependencies []string  // Import dependencies
	LastModified time.Time // Last modification time
	ContentHash  string    // Hash of source content
	WasFromCache bool      // Whether this component was loaded from cache
}

type ErrorData added in v0.5.0

type ErrorData struct {
	Status     int
	StatusText string
	Message    string
	Path       string
	Method     string
	RequestID  string
}

ErrorData represents the data passed to error templates

type ErrorHandler added in v0.5.0

type ErrorHandler struct {
	// contains filtered or unexported fields
}

ErrorHandler handles HTTP errors with custom error pages

func NewErrorHandler added in v0.5.0

func NewErrorHandler(fs filesystem.FileSystem, templateHandler *TemplateHandler) *ErrorHandler

NewErrorHandler creates a new error handler

func NewErrorHandlerWithRoutesDir added in v0.5.0

func NewErrorHandlerWithRoutesDir(fs filesystem.FileSystem, templateHandler *TemplateHandler, routesDir string) *ErrorHandler

NewErrorHandlerWithRoutesDir creates a new error handler with custom routes directory

func (*ErrorHandler) Handle404 added in v0.5.0

func (eh *ErrorHandler) Handle404(w http.ResponseWriter, r *http.Request)

Handle404 is a convenience method for 404 errors

func (*ErrorHandler) Handle500 added in v0.5.0

func (eh *ErrorHandler) Handle500(w http.ResponseWriter, r *http.Request, err error)

Handle500 is a convenience method for 500 errors

func (*ErrorHandler) ServeError added in v0.5.0

func (eh *ErrorHandler) ServeError(w http.ResponseWriter, r *http.Request, status int, message string)

ServeError serves an error response with the given status code and message

type ImportTransformer added in v0.5.0

type ImportTransformer struct {
	// contains filtered or unexported fields
}

ImportTransformer handles transformation of imports in JavaScript/TypeScript code

func NewImportTransformer added in v0.5.0

func NewImportTransformer(fs filesystem.FileSystem) *ImportTransformer

NewImportTransformer creates a new import transformer

func (*ImportTransformer) GetAssetType added in v0.5.0

func (it *ImportTransformer) GetAssetType(path string) string

GetAssetType determines the type of asset based on file extension

func (*ImportTransformer) GetPublicURL added in v0.5.0

func (it *ImportTransformer) GetPublicURL(assetPath string) string

GetPublicURL converts a filesystem path to a public URL

func (*ImportTransformer) ReplaceAssetImport added in v0.5.0

func (it *ImportTransformer) ReplaceAssetImport(jsCode, importName, importPath, assetPath, assetType string) string

ReplaceAssetImport handles non-component asset imports

func (*ImportTransformer) ResolveAssetPath added in v0.5.0

func (it *ImportTransformer) ResolveAssetPath(importPath string, currentPath string) (string, string)

ResolveAssetPath attempts to find an asset in various locations

func (*ImportTransformer) TransformImports added in v0.5.0

func (it *ImportTransformer) TransformImports(jsCode string, currentPath string, componentExtensions []string) (string, map[string]string)

TransformImports processes all imports in the given JavaScript code It returns the transformed code and a map of component imports (for framework-specific handling)

func (*ImportTransformer) TransformJSModule added in v0.5.0

func (it *ImportTransformer) TransformJSModule(jsContent string, importName string) string

TransformJSModule transforms a JavaScript module to make its exports available

type JSEnginePool added in v0.3.0

type JSEnginePool struct {
	// contains filtered or unexported fields
}

JSEnginePool manages a pool of JavaScript engines

func GetJSEnginePool added in v0.3.0

func GetJSEnginePool(fs filesystem.FileSystem, version string) *JSEnginePool

GetJSEnginePool returns a JavaScript engine pool for the given filesystem

func (*JSEnginePool) GetEngine added in v0.3.0

func (pool *JSEnginePool) GetEngine() (*SharedJSEngine, error)

GetEngine gets an available engine from the pool

func (*JSEnginePool) GetEngineForSession added in v0.3.0

func (pool *JSEnginePool) GetEngineForSession(sessionID string) (*SharedJSEngine, error)

GetEngineForSession gets an engine specifically for a session/client

func (*JSEnginePool) ReleaseSessionEngine added in v0.3.0

func (pool *JSEnginePool) ReleaseSessionEngine(sessionID string)

ReleaseSessionEngine releases an engine from a session (for cleanup)

func (*JSEnginePool) ReturnEngine added in v0.3.0

func (pool *JSEnginePool) ReturnEngine(engine *SharedJSEngine)

ReturnEngine returns an engine to the pool

func (*JSEnginePool) Stop added in v0.3.0

func (pool *JSEnginePool) Stop()

Stop stops all engines in the pool

type JavaScriptHandler

type JavaScriptHandler struct {
	// contains filtered or unexported fields
}

func NewJavaScriptHandler

func NewJavaScriptHandler(fs filesystem.FileSystem) *JavaScriptHandler

func NewJavaScriptHandlerWithVersion

func NewJavaScriptHandlerWithVersion(fs filesystem.FileSystem, version string) *JavaScriptHandler

func (*JavaScriptHandler) Handle

func (jh *JavaScriptHandler) Handle(route Route) http.HandlerFunc

func (*JavaScriptHandler) SetErrorHandler added in v0.5.0

func (jh *JavaScriptHandler) SetErrorHandler(eh *ErrorHandler)

type PrecompilePriority added in v0.5.0

type PrecompilePriority struct {
	Path     string
	Priority float64
	Size     int64
}

PrecompilePriority represents the priority of a file for precompilation

type PrecompileStats added in v0.5.0

type PrecompileStats struct {
	TotalFiles     int
	ProcessedFiles int
	FailedFiles    int
	SkippedFiles   int
	TotalTime      time.Duration
	StartTime      time.Time
}

PrecompileStats tracks precompilation statistics

type Route

type Route struct {
	Path      string
	FilePath  string
	FileType  string
	IsDynamic bool
	ParamName string
}

Route represents a single route in the application

type SharedJSEngine added in v0.3.0

type SharedJSEngine struct {
	// contains filtered or unexported fields
}

SharedJSEngine manages a shared JavaScript environment with module caching

func (*SharedJSEngine) ExecuteHTTPMethod added in v0.3.0

func (engine *SharedJSEngine) ExecuteHTTPMethod(r *http.Request, w http.ResponseWriter, route Route) error

ExecuteHTTPMethod executes an HTTP method handler from a JavaScript module

func (*SharedJSEngine) Start added in v0.3.0

func (engine *SharedJSEngine) Start() error

Start initializes the shared JavaScript engine

func (*SharedJSEngine) Stop added in v0.3.0

func (engine *SharedJSEngine) Stop()

Stop shuts down the shared JavaScript engine

type SvelteCompileResult added in v0.4.0

type SvelteCompileResult struct {
	JS  string `json:"js"`
	CSS string `json:"css"`
}

type SvelteConfig added in v0.4.0

type SvelteConfig struct {
	// Minification settings
	MinifyRuntime    bool // Enable runtime minification
	MinifyComponents bool // Enable component code minification
	MinifyCSS        bool // Enable CSS minification
	DevMode          bool // Disable minification in development

	// Runtime resource settings
	UseExternalRuntime   bool          // Use external runtime file instead of inline
	RuntimePath          string        // Path for runtime resource (default: "/svelte/runtime.js")
	RuntimeCacheDuration time.Duration // Cache duration for runtime resource

	// Async component loading settings
	EnableAsyncLoading     bool          // Enable async component loading
	ComponentCacheDuration time.Duration // Cache duration for component resources
	AsyncLibraryPath       string        // Path for async library (default: "/svelte/async.js")

	// Vimesh Style settings
	VimeshStyle     *utils.VimeshStyleConfig // Vimesh Style configuration
	VimeshStylePath string                   // Path for Vimesh Style resource (default: "/svelte/vimesh-style.js")
}

SvelteConfig holds all Svelte-related settings

func DefaultSvelteConfig added in v0.4.0

func DefaultSvelteConfig() *SvelteConfig

DefaultSvelteConfig returns default Svelte settings

type SvelteHandler added in v0.4.0

type SvelteHandler struct {
	// contains filtered or unexported fields
}

func NewSvelteHandler added in v0.4.0

func NewSvelteHandler(fs filesystem.FileSystem) *SvelteHandler

func NewSvelteHandlerWithConfig added in v0.4.0

func NewSvelteHandlerWithConfig(fs filesystem.FileSystem, config *SvelteConfig) *SvelteHandler

func NewSvelteHandlerWithRouter added in v0.4.0

func NewSvelteHandlerWithRouter(fs filesystem.FileSystem, config *SvelteConfig, router *mux.Router) *SvelteHandler

NewSvelteHandlerWithRouter creates a SvelteHandler and registers runtime routes

func NewSvelteHandlerWithRouterAndRoutesDir added in v0.5.0

func NewSvelteHandlerWithRouterAndRoutesDir(fs filesystem.FileSystem, config *SvelteConfig, router *mux.Router, routesDir string) *SvelteHandler

NewSvelteHandlerWithRouterAndRoutesDir creates a SvelteHandler with custom routes directory

func (*SvelteHandler) CanHandle added in v0.5.0

func (sh *SvelteHandler) CanHandle(requestPath string) bool

CanHandle implements ComponentHandler interface

func (*SvelteHandler) GetAllSvelteFiles added in v0.5.0

func (sh *SvelteHandler) GetAllSvelteFiles() ([]string, error)

GetAllSvelteFiles returns all Svelte files in the routes directory

func (*SvelteHandler) Handle added in v0.4.0

func (sh *SvelteHandler) Handle(route Route) http.HandlerFunc

func (*SvelteHandler) PrecompileComponent added in v0.5.0

func (sh *SvelteHandler) PrecompileComponent(filePath string, content string) error

PrecompileComponent pre-compiles a Svelte component and stores it in cache

func (*SvelteHandler) RegisterRoutes added in v0.4.0

func (sh *SvelteHandler) RegisterRoutes(router *mux.Router)

RegisterRoutes registers Svelte-related routes

func (*SvelteHandler) ServeAsyncComponent added in v0.4.1

func (sh *SvelteHandler) ServeAsyncComponent(w http.ResponseWriter, r *http.Request)

ServeAsyncComponent serves individual components as JSON for async loading

func (*SvelteHandler) ServeAsyncLibrary added in v0.4.1

func (sh *SvelteHandler) ServeAsyncLibrary(w http.ResponseWriter, r *http.Request)

ServeAsyncLibrary serves the async component loading library

func (*SvelteHandler) ServeComponent added in v0.5.0

func (sh *SvelteHandler) ServeComponent(w http.ResponseWriter, r *http.Request)

ServeComponent implements ComponentHandler interface

func (*SvelteHandler) ServeSvelteRuntime added in v0.4.0

func (sh *SvelteHandler) ServeSvelteRuntime(w http.ResponseWriter, r *http.Request)

ServeSvelteRuntime serves the Svelte runtime as a static resource

func (*SvelteHandler) ServeVimeshStyle added in v0.4.0

func (sh *SvelteHandler) ServeVimeshStyle(w http.ResponseWriter, r *http.Request)

ServeVimeshStyle serves the Vimesh Style JavaScript as a static resource

func (*SvelteHandler) SetPersistentCache added in v0.5.0

func (sh *SvelteHandler) SetPersistentCache(cache *cache.SvelteCache)

SetPersistentCache sets the persistent cache for the handler

type SveltePrecompiler added in v0.5.0

type SveltePrecompiler struct {
	// contains filtered or unexported fields
}

SveltePrecompiler handles background precompilation of Svelte components

func NewSveltePrecompiler added in v0.5.0

func NewSveltePrecompiler(fs filesystem.FileSystem, cache *cache.SvelteCache, handler *SvelteHandler, routesDir string, workers int) *SveltePrecompiler

NewSveltePrecompiler creates a new precompiler instance

func (*SveltePrecompiler) GetProgress added in v0.5.0

func (sp *SveltePrecompiler) GetProgress() float64

GetProgress returns the current progress percentage

func (*SveltePrecompiler) GetStats added in v0.5.0

func (sp *SveltePrecompiler) GetStats() PrecompileStats

GetStats returns current precompilation statistics

func (*SveltePrecompiler) IsComplete added in v0.5.0

func (sp *SveltePrecompiler) IsComplete() bool

IsComplete returns whether precompilation is complete

func (*SveltePrecompiler) Start added in v0.5.0

func (sp *SveltePrecompiler) Start() error

Start begins the precompilation process

func (*SveltePrecompiler) Stop added in v0.5.0

func (sp *SveltePrecompiler) Stop()

Stop stops the precompilation process

type TemplateConfig added in v0.5.0

type TemplateConfig struct {
	// Vimesh Style settings
	VimeshStyle     *utils.VimeshStyleConfig // Vimesh Style configuration
	VimeshStylePath string                   // Path for Vimesh Style resource (default: "/vimesh-style.js")
	MinifyVimesh    bool                     // Enable Vimesh Style minification
	DevMode         bool                     // Development mode (disable minification)
}

TemplateConfig holds all template-related settings

func DefaultTemplateConfig added in v0.5.0

func DefaultTemplateConfig() *TemplateConfig

DefaultTemplateConfig returns default template settings

type TemplateHandler added in v0.3.0

type TemplateHandler struct {
	// contains filtered or unexported fields
}

func NewTemplateHandler added in v0.3.0

func NewTemplateHandler(fs filesystem.FileSystem) *TemplateHandler

func NewTemplateHandlerWithConfig added in v0.5.0

func NewTemplateHandlerWithConfig(fs filesystem.FileSystem, config *TemplateConfig) *TemplateHandler

func NewTemplateHandlerWithRouter added in v0.5.0

func NewTemplateHandlerWithRouter(fs filesystem.FileSystem, config *TemplateConfig, router *mux.Router) *TemplateHandler

NewTemplateHandlerWithRouter creates a TemplateHandler with router for registering routes

func (*TemplateHandler) Handle added in v0.3.0

func (th *TemplateHandler) Handle(route Route) http.HandlerFunc

func (*TemplateHandler) RegisterRoutes added in v0.5.0

func (th *TemplateHandler) RegisterRoutes(router *mux.Router)

RegisterRoutes registers additional routes for the template handler

func (*TemplateHandler) RenderTemplate added in v0.3.0

func (th *TemplateHandler) RenderTemplate(templatePath, templateContent string, data interface{}, w http.ResponseWriter) error

RenderTemplate renders a template file with the given data

func (*TemplateHandler) ServeVimeshStyle added in v0.5.0

func (th *TemplateHandler) ServeVimeshStyle(w http.ResponseWriter, r *http.Request)

ServeVimeshStyle serves the Vimesh Style JavaScript as a static resource

type VMManager added in v0.2.0

type VMManager struct {
	// contains filtered or unexported fields
}

VMManager manages JavaScript VM creation and module initialization

func NewVMManager added in v0.2.0

func NewVMManager(fs filesystem.FileSystem, version string) *VMManager

NewVMManager creates a new VM manager

func (*VMManager) SetupRegistry added in v0.2.0

func (vm *VMManager) SetupRegistry(loop *eventloop.EventLoop, jsVM *js.Runtime, basePath string) (*require.Registry, *require.RequireModule, error)

SetupRegistry creates and configures a require registry with all modules

Jump to

Keyboard shortcuts

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