Documentation
¶
Index ¶
- Constants
- func EvaluateExpr(code string) (string, error)
- func ToMap(v any) (map[string]any, bool)
- func ToNative(v any) any
- type APIRequest
- type APIResult
- type APIRouteRuntime
- type MiddlewareRequest
- type MiddlewareResult
- type MiddlewareRuntime
- type Runtime
- func (r *Runtime) Call(function string, args ...any) (any, error)
- func (r *Runtime) CallValue(function string, args ...any) (quickjs.Value, error)
- func (r *Runtime) Close() error
- func (r *Runtime) DrainJobs()
- func (r *Runtime) Execute(code string) (any, error)
- func (r *Runtime) ExecuteModule(code string) (any, error)
- func (r *Runtime) GetGlobal(name string) (any, error)
- func (r *Runtime) RegisterFunc(name string, f func(args []any) (any, error)) error
- func (r *Runtime) RegisterFuncWithThis(name string, f func(this quickjs.Value, args []any) (any, error)) error
- func (r *Runtime) SetEnv(env map[string]string) error
- func (r *Runtime) SetGlobal(name string, value any) error
- func (r *Runtime) VM() *quickjs.VM
Constants ¶
const ( // EvalGlobal evaluates in the global scope EvalGlobal = quickjs.EvalGlobal // EvalModule evaluates as an ES module EvalModule = quickjs.EvalModule )
Variables ¶
This section is empty.
Functions ¶
func EvaluateExpr ¶
EvaluateExpr evaluates a self-contained JS expression in a fresh QuickJS VM and returns its String() representation. Because QuickJS is a full ECMAScript engine, every built-in (Date, Math, String, Number, Array, Object, ...) is available — so SSR evaluation of globals like Date.now() produces a genuine JS-engine value rather than a Go approximation. Returns an error when the expression throws (e.g. it references an identifier that isn't defined).
Types ¶
type APIRequest ¶
type APIRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
}
APIRequest is the input to an API route handler
type APIResult ¶
type APIResult struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Error string `json:"error"`
}
APIResult is the output of an API route handler
type APIRouteRuntime ¶
type APIRouteRuntime struct {
// contains filtered or unexported fields
}
APIRouteRuntime executes compiled API routes via embedded quickjs
func NewAPIRouteRuntime ¶
func NewAPIRouteRuntime(apiDir string) *APIRouteRuntime
NewAPIRouteRuntime creates a new API route runtime
func (*APIRouteRuntime) Execute ¶
func (a *APIRouteRuntime) Execute(req APIRequest) APIResult
Execute runs the API route handler for the given path
type MiddlewareRequest ¶
type MiddlewareRequest struct {
URL string `json:"url"`
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
}
MiddlewareRequest is the input to the middleware function
type MiddlewareResult ¶
type MiddlewareResult struct {
Action string `json:"action"`
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
Error string `json:"error"`
}
MiddlewareResult is the output of the middleware function
type MiddlewareRuntime ¶
type MiddlewareRuntime struct {
// contains filtered or unexported fields
}
MiddlewareRuntime executes middleware.ts via embedded quickjs
func LoadMiddlewareRuntime ¶
func LoadMiddlewareRuntime(root string) *MiddlewareRuntime
LoadMiddlewareRuntime loads the middleware.js and returns a runtime, or nil if no middleware
func NewMiddlewareRuntime ¶
func NewMiddlewareRuntime(middlewarePath string) (*MiddlewareRuntime, error)
NewMiddlewareRuntime creates a new middleware runtime and loads the middleware.js
func (*MiddlewareRuntime) Close ¶
func (m *MiddlewareRuntime) Close()
Close releases the runtime resources
func (*MiddlewareRuntime) Execute ¶
func (m *MiddlewareRuntime) Execute(req MiddlewareRequest) MiddlewareResult
Execute runs the middleware with the given request and returns the result
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime wraps a quickjs VM with krate-specific Web API polyfills
func (*Runtime) DrainJobs ¶
func (r *Runtime) DrainJobs()
DrainJobs executes pending promise jobs (microtasks). Call after Execute to resolve promises.
func (*Runtime) ExecuteModule ¶
ExecuteModule evaluates JavaScript code as an ES module
func (*Runtime) RegisterFunc ¶
RegisterFunc registers a Go function as a global JS function
func (*Runtime) RegisterFuncWithThis ¶
func (r *Runtime) RegisterFuncWithThis(name string, f func(this quickjs.Value, args []any) (any, error)) error
RegisterFuncWithThis registers a Go function that receives the this object