Help us shape the future of Go! Take the 2026 Go Developer Survey

scripting

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JavaScriptLanguage 是脚本表中 JavaScript 的稳定语言标识。
	JavaScriptLanguage = "JAVASCRIPT"
	// LuaLanguage 是脚本表中 Lua 的稳定语言标识。
	LuaLanguage = "LUA"
	// PythonLanguage 是脚本表中 Python 的稳定语言标识。
	PythonLanguage = "PYTHON"
	// GoLanguage 是脚本表中 Go 的稳定语言标识。
	GoLanguage = "GO"
	// WasmLanguage 是脚本表中 WebAssembly 的稳定语言标识。
	WasmLanguage = "WASM"
	// CELLanguage 是脚本表中 CEL 的稳定语言标识。
	CELLanguage = "CEL"
	// ExprLanguage 是脚本表中 Expr 的稳定语言标识。
	ExprLanguage = "EXPR"
	// StarlarkLanguage 是脚本表中 Starlark 的稳定语言标识。
	StarlarkLanguage = "STARLARK"
	// TclLanguage 是脚本表中 TCL 的稳定语言标识。
	TclLanguage = "TCL"
	// DefaultTimeout 是单次脚本执行的最大耗时。
	DefaultTimeout = 5 * time.Second
	// MaxContextBytes 是单次脚本上下文允许的最大 JSON 大小。
	MaxContextBytes = 200 * 1024
)

Variables

View Source
var ProviderSet = wire.NewSet(NewRuntime)

ProviderSet 提供脚本运行时的依赖注入集合。

Functions

func MarshalOutput

func MarshalOutput(value any) (string, error)

MarshalOutput 将脚本结果编码为管理端展示用 JSON。

func ParseContext

func ParseContext(raw string) (map[string]any, error)

ParseContext 将 JSON 上下文解析为脚本可用的对象。

Types

type Runtime

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

Runtime 负责创建隔离的脚本执行实例。

func NewRuntime

func NewRuntime() *Runtime

NewRuntime 创建脚本执行运行时。

func (*Runtime) Execute

func (r *Runtime) Execute(ctx context.Context, language string, source string, input map[string]any) (any, error)

Execute 执行一段指定语言的源码并返回脚本输出。 输入按 JSON 深拷贝隔离;支持结构化全局变量的引擎通过 ctx 读取上下文。 超时依赖引擎支持取消;GPython、Starlark、TCL 等现有适配器不保证硬中断。

func (*Runtime) ExecuteWorkflow added in v0.1.0

func (r *Runtime) ExecuteWorkflow(ctx context.Context, language string, source string, input map[string]any) (any, error)

ExecuteWorkflow 使用不注册宿主模块的纯 JavaScript VM 执行流程脚本。 仅注入原生 JSON 上下文,不提供 process、require、文件、网络或 Go 对象能力。

Jump to

Keyboard shortcuts

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