Documentation
¶
Index ¶
- Constants
- Variables
- func CLearModules()
- func Call(options CallOptions, source string, args ...interface{}) (interface{}, error)
- func DisablePrecompile()
- func EnableDebug()
- func EnablePrecompile()
- func Exists(id string) bool
- func GetModuleName(file string) string
- func MakeTemplate(iso *v8go.Isolate) *v8go.ObjectTemplate
- func PrintException(method string, args []interface{}, jserr *v8go.JSError, ...)
- func RegisterFunction(name string, function EmbedFunction, attributes ...v8go.PropertyAttribute) error
- func RegisterObject(name string, object EmbedObject, attributes ...v8go.PropertyAttribute) error
- func Require(iso *v8go.Isolate) *v8go.FunctionTemplate
- func SelectIsoStandard(timeout time.Duration) (*store.Isolate, error)
- func SetHeapAvailableSize(size uint)
- func StackTrace(jserr *v8go.JSError, rootMapping interface{}) string
- func Start(option *Option) error
- func Stop()
- func Transform(source string, globalName string) string
- func TransformTS(file string, source []byte) ([]byte, error)
- type CallOptions
- type Context
- func (context *Context) Call(method string, args ...interface{}) (interface{}, error)
- func (context *Context) CallAnonymous(source string, args ...interface{}) (interface{}, error)
- func (context *Context) CallAnonymousWith(ctx context.Context, source string, args ...interface{}) (interface{}, error)
- func (context *Context) CallWith(ctx context.Context, method string, args ...interface{}) (interface{}, error)
- func (context *Context) Close() error
- func (context *Context) WithAuthorized(authorized map[string]interface{}) *Context
- func (context *Context) WithFunction(name string, cb v8go.FunctionCallback)
- func (context *Context) WithGlobal(name string, value interface{}) error
- type Dispatcher
- type EmbedFunction
- type EmbedObject
- type Health
- type ID
- type Import
- type Isolate
- type Isolates
- type Module
- type Option
- type Runner
- func (runner *Runner) Context() (*v8go.Context, error)
- func (runner *Runner) Destroy(cb func())
- func (runner *Runner) Exec(script *Script) interface{}
- func (runner *Runner) ExecWithContext(ctx context.Context, script *Script) interface{}
- func (runner *Runner) Reset()
- func (runner *Runner) Start(ready chan bool) error
- type Script
- func Load(file string, id string) (*Script, error)
- func LoadRoot(file string, id string) (*Script, error)
- func MakeScript(source []byte, file string, timeout time.Duration, isroot ...bool) (*Script, error)
- func MakeScriptInMemory(source []byte, virtualFile string, timeout time.Duration, isroot ...bool) (*Script, error)
- func NewScript(file string, id string, timeout ...time.Duration) *Script
- func Select(id string) (*Script, error)
- func SelectRoot(id string) (*Script, error)
- type SourceMap
- type StackLogEntry
- type StackLogEntryList
- type TSConfig
- type TSConfigCompilerOptions
- type ThirdPartyFunction
- type ThirdPartyObject
Constants ¶
const ( // RunnerStatusInit is the runner status init RunnerStatusInit uint8 = iota // RunnerStatusRunning is the runner status running RunnerStatusRunning // RunnerStatusCleaning is the runner status cleaning RunnerStatusCleaning // RunnerStatusReady is the runner status ready RunnerStatusReady // RunnerStatusDestroy is the runner status destroy RunnerStatusDestroy // RunnerCommandDestroy is the runner command destroy RunnerCommandDestroy // RunnerCommandReset is the runner command reset RunnerCommandReset // RunnerCommandExec is the runner command exec RunnerCommandExec // RunnerCommandStatus is the runner command status RunnerCommandStatus )
const ( // IsoReady isolate is ready IsoReady uint8 = 0 // IsoBusy isolate is in used IsoBusy uint8 = 1 )
Variables ¶
var ImportMap = map[string][]Import{}
ImportMap the import maps
var ModuleSourceMaps = map[string][]byte{}
ModuleSourceMaps the source maps for modules
var Modules = map[string]Module{}
Modules the scripts for modules
var RootScripts = map[string]*Script{}
RootScripts the scripts for studio
var Scripts = map[string]*Script{}
Scripts loaded scripts
var SourceCodes = map[string][]byte{}
SourceCodes the source codes
var SourceMaps = map[string][]byte{}
SourceMaps the source maps
Functions ¶
func Call ¶ added in v1.0.0
func Call(options CallOptions, source string, args ...interface{}) (interface{}, error)
Call call the function directly
func GetModuleName ¶ added in v1.0.0
GetModuleName get the module name
func MakeTemplate ¶ added in v1.0.0
func MakeTemplate(iso *v8go.Isolate) *v8go.ObjectTemplate
MakeTemplate make a new template
func PrintException ¶ added in v1.0.0
func PrintException(method string, args []interface{}, jserr *v8go.JSError, rootMapping interface{})
PrintException print the exception
func RegisterFunction ¶ added in v1.0.0
func RegisterFunction(name string, function EmbedFunction, attributes ...v8go.PropertyAttribute) error
RegisterFunction register a third party function
func RegisterObject ¶ added in v1.0.0
func RegisterObject(name string, object EmbedObject, attributes ...v8go.PropertyAttribute) error
RegisterObject register a third party object
func Require ¶ added in v1.0.0
func Require(iso *v8go.Isolate) *v8go.FunctionTemplate
Require function template
func SelectIsoStandard ¶ added in v1.0.0
SelectIsoStandard creates a new isolate synchronously for each request Standard mode design: create on-demand, use immediately, dispose after use
func SetHeapAvailableSize ¶
func SetHeapAvailableSize(size uint)
SetHeapAvailableSize set runtime Available
func StackTrace ¶ added in v1.0.0
StackTrace get the stack trace
Types ¶
type CallOptions ¶ added in v1.0.0
CallOptions call options
type Context ¶
type Context struct {
ID string // the script id
Sid string // set the session id
Data map[string]interface{} // set the global data
Authorized map[string]interface{} // authorized information (optional)
Root bool
Timeout time.Duration // terminate the execution after this time
SourceRoots interface{} // the script source root mappping
*Runner
*store.Isolate
*v8go.UnboundScript
*v8go.Context
// contains filtered or unexported fields
}
Context v8 Context
func (*Context) CallAnonymous ¶ added in v1.0.0
CallAnonymous call the script function with anonymous function
func (*Context) CallAnonymousWith ¶ added in v1.0.0
func (context *Context) CallAnonymousWith(ctx context.Context, source string, args ...interface{}) (interface{}, error)
CallAnonymousWith call the script function with anonymous function
func (*Context) CallWith ¶ added in v1.0.0
func (context *Context) CallWith(ctx context.Context, method string, args ...interface{}) (interface{}, error)
CallWith call the script function
func (*Context) WithAuthorized ¶ added in v1.0.0
WithAuthorized set the authorized information for the context
func (*Context) WithFunction ¶ added in v1.0.0
func (context *Context) WithFunction(name string, cb v8go.FunctionCallback)
WithFunction add a function to the context
func (*Context) WithGlobal ¶ added in v1.0.0
WithGlobal add a global variable to the context
type Dispatcher ¶ added in v1.0.0
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is a runner dispatcher
func NewDispatcher ¶ added in v1.0.0
func NewDispatcher(min, max uint) *Dispatcher
NewDispatcher is a runner dispatcher
func (*Dispatcher) Scaling ¶ added in v1.0.0
func (dispatcher *Dispatcher) Scaling()
Scaling scale the v8 runners, check every 10 seconds Release the v8 runners if the free runners are more than max size Create a new v8 runner if the free runners are less than min size
func (*Dispatcher) Select ¶ added in v1.0.0
func (dispatcher *Dispatcher) Select(timeout time.Duration) (*Runner, error)
Select select a free v8 runner
func (*Dispatcher) Start ¶ added in v1.0.0
func (dispatcher *Dispatcher) Start() error
Start start the v8 mannager
func (*Dispatcher) Stop ¶ added in v1.0.0
func (dispatcher *Dispatcher) Stop()
Stop stop the v8 mannager
type EmbedFunction ¶ added in v1.0.0
type EmbedFunction func(iso *v8go.Isolate) *v8go.FunctionTemplate
EmbedFunction embed function
type EmbedObject ¶ added in v1.0.0
type EmbedObject func(iso *v8go.Isolate) *v8go.ObjectTemplate
EmbedObject embed object
type Health ¶ added in v1.0.0
type Health struct {
// contains filtered or unexported fields
}
Health is the health check
type Option ¶
type Option struct {
Mode string `json:"mode,omitempty"` // the mode of the runtime, the default value is "standard" and the other value is "performance". "performance" mode need more memory but will run faster
MinSize uint `json:"minSize,omitempty"` // the number of V8 VM when runtime start. max value is 100, the default value is 2
MaxSize uint `json:"maxSize,omitempty"` // the maximum of V8 VM should be smaller than minSize, the default value is 10
HeapSizeLimit uint64 `json:"heapSizeLimit,omitempty"` // the isolate heap size limit should be smaller than 1.5G, and the default value is 1518338048 (1.5G)
HeapSizeRelease uint64 `json:"heapSizeRelease,omitempty"` // the isolate will be re-created when reaching this value, and the default value is 52428800 (50M)
HeapAvailableSize uint64 `json:"heapAvailableSize,omitempty"` // the isolate will be re-created when the available size is smaller than this value, and the default value is 524288000 (500M)
Precompile bool `json:"precompile,omitempty"` // if true compile scripts when the VM is created. this will increase the load time, but the script will run faster. the default value is false
DefaultTimeout int `json:"defaultTimeout,omitempty"` // the default timeout for the script, the default value is 200ms
ContextTimeout int `json:"contextTimeout,omitempty"` // the default timeout for the context, the default value is 200ms
ContetxQueueSize int `json:"contextQueueSize,omitempty"` // the default queue size for the context, the default value is 10, performance only
DataRoot string `json:"dataRoot,omitempty"` // the data root path
TSConfig *TSConfig `json:"tsconfig,omitempty"` // the TypeScript config
Debug bool `json:"debug,omitempty"` // if true, the debug mode will be enabled, default value is false
ConsoleMode string `json:"consoleMode,omitempty"` // the console mode, default value is "production", the other value is "development"
// The following options are experimental features and not stable.
// They may be removed once the features become stable. Please do not use them in a production environment.
Import bool `json:"import,omitempty"` // Always true, do not change it.
}
Option runtime option
type Runner ¶ added in v1.0.0
type Runner struct {
// contains filtered or unexported fields
}
Runner is the v8 runner
func (*Runner) Destroy ¶ added in v1.0.0
func (runner *Runner) Destroy(cb func())
Destroy send a destroy signal to the v8 runner
func (*Runner) ExecWithContext ¶ added in v1.0.0
ExecWithContext send a script to the v8 runner to execute with context cancellation support
type Script ¶
type Script struct {
ID string
File string
Source string
Root bool
SourceRoots interface{} // the script source root mappping
Timeout time.Duration
}
Script v8 scripts
func MakeScript ¶ added in v1.0.0
MakeScript make a script from source
func MakeScriptInMemory ¶ added in v1.0.0
func MakeScriptInMemory(source []byte, virtualFile string, timeout time.Duration, isroot ...bool) (*Script, error)
MakeScriptInMemory creates a script from source code without file system access. This is useful for scripts stored in database or generated dynamically. Supports TypeScript syntax but NOT imports (since there's no file to resolve). For scripts with imports, use MakeScript with a real file path.
func SelectRoot ¶
SelectRoot a script with root privileges
func (*Script) ContextTimeout ¶ added in v1.0.0
ContextTimeout get the context timeout
func (*Script) Exec ¶ added in v1.0.0
Exec execute the script the default mode is "standard" and the other value is "performance". the "standard" mode save memory but will run slower. can be used in most cases, especially in arm64 device. the "performance" mode need more memory but will run faster. can be used in high concurrency and large script.
func (*Script) NewContext ¶
NewContext create a new context
type SourceMap ¶ added in v1.0.0
type SourceMap struct {
Version int `json:"version"`
File string `json:"file"`
SourceRoot string `json:"sourceRoot,omitempty"`
Sources []string `json:"sources"`
Names []string `json:"names"`
Mappings string `json:"mappings"`
SourcesContent []string `json:"sourcesContent,omitempty"`
// contains filtered or unexported fields
}
SourceMap source map
func NewSourceMap ¶ added in v1.0.0
NewSourceMap create a new source map
type StackLogEntry ¶ added in v1.0.0
type StackLogEntry struct {
Function string `json:"function,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Column int `json:"column,omitempty"`
Message string `json:"message,omitempty"`
}
StackLogEntry stack log entry
func (*StackLogEntry) String ¶ added in v1.0.0
func (entry *StackLogEntry) String() string
type StackLogEntryList ¶ added in v1.0.0
type StackLogEntryList []*StackLogEntry
StackLogEntryList stack log entry list
func (StackLogEntryList) String ¶ added in v1.0.0
func (list StackLogEntryList) String(rootMapping interface{}) (string, error)
String the stack log entry list to string
type TSConfig ¶ added in v1.0.0
type TSConfig struct {
CompilerOptions *TSConfigCompilerOptions `json:"compilerOptions,omitempty"`
Exclude []string `json:"exclude,omitempty"`
}
TSConfig TypeScript config
func (*TSConfig) GetFileName ¶ added in v1.0.0
GetFileName get the file name from the tsconfig
func (*TSConfig) ReplacePattern ¶ added in v1.0.0
ReplacePattern replace the pattern
type TSConfigCompilerOptions ¶ added in v1.0.0
type TSConfigCompilerOptions struct {
Target string `json:"target,omitempty"`
Paths map[string][]string `json:"paths,omitempty"`
Lib []string `json:"lib,omitempty"`
}
TSConfigCompilerOptions TypeScript compiler options
type ThirdPartyFunction ¶ added in v1.0.0
type ThirdPartyFunction struct {
Name string
Function EmbedFunction
Attributes []v8go.PropertyAttribute
}
ThirdPartyFunction third party function
type ThirdPartyObject ¶ added in v1.0.0
type ThirdPartyObject struct {
Name string
Object EmbedObject
Attributes []v8go.PropertyAttribute
}
ThirdPartyObject third party object