Documentation
¶
Index ¶
Constants ¶
const ( Unlimited = -1 // Unlimited number fo concurrency MaxExecutionTime = 5 * time.Minute // Default maximum execution time to 5 minutes )
Variables ¶
var ( ErrEntryAlreadyRegistered = errors.New("entry already registered") ErrEntryDoesNotExists = errors.New("entry does not exists") ErrUnsupportedConfigFormat = errors.New("unsupported configuration file format") ErrBytecodeNotReady = errors.New("bytecode not ready") ErrInvalidBytecode = errors.New("invalid bytecode") ErrBytecodeNotRecompilable = errors.New("can not recompile bytecode") )
List of known errors
Functions ¶
func GetImportableModuleMap ¶
func GetImportableModuleMap(modules []string) *tengo.ModuleMap
GetImportableModuleMap from given modules name. Search module from stdlib and tnglib
Types ¶
type Config ¶
type Config struct { MaxExecutionTime tnglib.Span `json:"maxExecutionTime"` EnableFileImport bool `json:"enableFileImport"` ImportDir string `json:"importDir"` MaxAllocs int64 `json:"maxAllocs"` MaxConstObjects int `json:"maxConstObjects"` ImportFileExt []string `json:"importFileExt"` Modules []string `json:"modules"` // empty means all modules InitVars map[string]interface{} `json:"initVars"` }
Config stores configuration for each script to be executed.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig create default configuration for script
func NewFileConfig ¶
NewFileConfig load configuration from given file. Supported formats: json
func (Config) ImportDirectory ¶
ImportDirectory for given srcFilename
func (Config) ImportFileExtensions ¶
func (Config) IsSourceFile ¶
IsSourceFile return true if extension is registered as compiled extension
type Entry ¶
type Entry interface { Configuration() Config CompiledAt() time.Time Age() time.Duration Runnable() Runnable Recompile() error SaveTo(filename string) error String() string }
Entry properties
func BytecodeFromBytes ¶
BytecodeFromBytes convert byte array to byte code
func BytecodeFromCompiled ¶
BytecodeFromCompiled loads compiled code from file
func BytecodeFromFile ¶
BytecodeFromFile create bytecode either from source or compiled
func BytecodeFromSource ¶
BytecodeFromSource compiles source file and then store it to bytecode
func BytecodeFromString ¶
BytecodeFromString convert base-64 encoded string to bytecode
type Executor ¶
type Executor interface { Exec(id string, inpVars map[string]interface{}, outVars ...string) ([]*tengo.Variable, error) ExecContext(ctx context.Context, id string, inpVars map[string]interface{}, outVars ...string) ([]*tengo.Variable, error) NumInProgress() int WaitAll(ctx context.Context) error }
Executor executes manages script
func NewExecutor ¶
NewExecutor create script executor with limited concurrency. If set to <= 0, then there will be no limit.
type Manager ¶
type Manager interface { Exists(id string) bool AddEntry(id string, e Entry) error Add(id string, data []byte) error AddFile(id, filename string, conf *Config) error Recompile(id string) error Entry(id string) Entry Remove(id string) bool Clear() Age(id string) (time.Duration, bool) }
Manager manages compiled script