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

runtime

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 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
	RootLoad(filename string, name string) error
	RootLoadReader(reader io.Reader, name string, filename ...string) error
	AddFunction(name string, fn func(global map[string]interface{}, sid string, args ...interface{}) interface{}) error
	AddRootFunction(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)
	RootCall(data map[string]interface{}, name string, method string, args ...interface{}) (interface{}, error)
}

Engine 脚本接口

type Option added in v0.10.2

type Option struct {
	FileRoot   string `json:"fileRoot,omitempty"`   // fileRoot
	WorkerNums int    `json:"workerNums,omitempty"` // workerNums
}

Option the runtime option

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) RootCall added in v0.10.2

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

RootCall 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(option Option) *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) AddRootFunction added in v0.10.2

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

AddRootFunction add a global JavaScript function (root only)

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

func (*Runtime) RootLoad added in v0.10.2

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

RootLoad load and compile script root mode

func (*Runtime) RootReader added in v0.10.2

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

RootReader load and compile script root mode

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