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

runtime

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine interface {
	Load(filename string, name string) error
	LoadReader(reader io.Reader, name string, filename ...string) error
	AddFunction(name string, fn func(global map[string]interface{}, sid string, args ...interface{}) interface{}) error
	AddObject(name string, methods map[string]func(global map[string]interface{}, sid string, args ...interface{}) interface{}) error
	Init() error

	Has(name string) bool
	Call(data map[string]interface{}, name string, method string, args ...interface{}) (interface{}, error)
}

Engine 脚本接口

type Request

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

Request 请求

func (*Request) Call

func (request *Request) Call(args ...interface{}) (interface{}, error)

Call execute JavaScript function and return

func (*Request) WithContext

func (request *Request) WithContext(context context.Context) *Request

WithContext with context

func (*Request) WithGlobal

func (request *Request) WithGlobal(data map[string]interface{}) *Request

WithGlobal with global data

func (*Request) WithSid

func (request *Request) WithSid(sid string) *Request

WithSid with global session id

type Runtime

type Runtime struct {
	Name    string
	Engine  Engine
	Scripts map[string]Script
}

Runtime 运行时

func Node

func Node() *Runtime

Node create a NodeJS runtime ( not support yet )

func Yao

func Yao(numOfContexts int) *Runtime

Yao create a pure javascript ES6 javascript runtime

func (*Runtime) AddFunction

func (runtime *Runtime) AddFunction(name string, fn func(global map[string]interface{}, sid string, args ...interface{}) interface{}) *Runtime

AddFunction add a global JavaScript function

func (*Runtime) AddObject

func (runtime *Runtime) AddObject(name string, methods map[string]func(global map[string]interface{}, sid string, args ...interface{}) interface{}) *Runtime

AddObject add a global JavaScript object

func (*Runtime) Has

func (runtime *Runtime) Has(name string) bool

Has check the given name of the script is load

func (*Runtime) Init

func (runtime *Runtime) Init() error

Init initialize Engine

func (*Runtime) Load

func (runtime *Runtime) Load(filename string, name string) error

Load load and compile script

func (*Runtime) LoadReader

func (runtime *Runtime) LoadReader(reader io.Reader, name string, filename ...string) error

LoadReader load and compile script

func (*Runtime) New

func (runtime *Runtime) New(name string, method string) *Request

New create a new ctx

type Script

type Script struct {
	File   string
	Source string
}

Script 脚本

Directories

Path Synopsis
yao

Jump to

Keyboard shortcuts

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