yocki

package
v0.0.0-...-9853328 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 5 Imported by: 0

README

Yock Interface

English | 简体中文

Yock Interface provides a mesh interface based on grpc and protobuf to help developers build Yock extensions quickly and easily. It's somewhat similar to microservices and requires constant local loopbacks. But the benefits are self-evident, and the use of networking supports more languages and is more convenient than intrusive (dynamic libraries).

API

Ping

Parameter: empty Return value: empty Function: Used to test whether the connection is reachable

Call

Parameters: Fn (string), Args (string) Return value: Buf (string) Function: The Call function is the core of the Interface, which receives the function name (Fn) and parameters (Args) to return Buf. This means that it can meet a large number of needs, through the free combination of function names and parameters, just like calling functions within the program, the return value can be in the serialized JSON, XML and other formats.

Documentation

Index

Constants

View Source
const (
	Y_STRICT = 1
	Y_DEBUG  = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvVar

type EnvVar interface {
	// SetPath set operate target:
	// windows: sys or user, it's required in windows.
	// posix: /etc/enviroment, this only is empty method.
	SetPath(string) error

	// set global enviroment variable
	Set(string, any) error
	// set global enviroment variable when key isn't exist
	SafeSet(string, any) error

	// unset (delete) global enviroment variable
	Unset(string) error

	// set local enviroment variable
	SetL(string, string) error
	// set local enviroment variable when key isn't exist
	SafeSetL(string, string) error

	// export current enviroment string into specify file
	Export(string) error
	// load enviroment string to be export from disk
	Load(EnvVarLoadOpt) error

	// Print current enviroment variable
	Print()
}

EnvVar is an interface to abstract different os enviroment variable

type EnvVarLoadOpt

type EnvVarLoadOpt struct {
	File string
	Keys []string
	Safe bool
}

type GoPool

type GoPool interface {
	Go(func())
	Run()
}

type LuaFuncs

type LuaFuncs map[string]lua.LGFunction

type Promise

type Promise interface {
	Load(id int64) (any, bool)
	LoadWithTimeout(id int64, timeout time.Duration) (any, bool)
	Store(id int64, v any)
	// NextID returns the unique snowflake id to ensure concurrency security
	NextID() int64
}

type PromiseEvent

type PromiseEvent interface {
	Id() int64
	Proto() Protocal
}

type Protocal

type Protocal interface {
	Type() pb.ProtocalType
	String() string
}

type SignalStream

type SignalStream interface {
	// Load returns the value of the specified singal.
	// If the singal isn't exist, the second parameter returns false, and vice versa.
	Load(sig string) (any, bool)
	// Store settings specify the value of the singal, similar to map's kv storage.
	Store(sig string, v bool)
}

SignalStream is an abstract interface for distributing and updating singals

type Table

type Table interface {
	TableAt
	TableSetter
	TableGetter
	SetDo(k string, v func(YockState) lua.LValue, env ...YockState)
	Bind(v any) error
	Clone(l *lua.LState) Table
	Value() *lua.LTable
}

type TableAt

type TableAt interface {
	ToString(n int) string
	ToTable(n int) Table
	ToFunctionByString(k string) *lua.LFunction
	ToFloat32ByString(k string) float32
	ToFloat64ByString(k string) float64
	ToIntByString(k string) int
	ToFunction(n int) *lua.LFunction
	ToFloat32(n int) float32
	ToFloat64(n int) float64
	ToInt(n int) int
}

type TableGetter

type TableGetter interface {
	GetBool(k string) (bool, bool)
	GetString(k string) (string, bool)
	GetInt(k string) (int, bool)
	GetFloat(k string) (float64, bool)
	GetTable(k string) (Table, bool)
	GetLTable(k string) (*lua.LTable, bool)
	MustGetTable(key string) Table
}

type TableSetter

type TableSetter interface {
	SetString(k, v string)
	SetBool(k string, v bool)
	SetNil(k string)
	SetInt(k string, v int)
	SetTable(k string, v Table)
	SetLTable(k string, v *lua.LTable)
	SetField(l *lua.LState, k string, v any)
	SetFields(l *lua.LState, v map[string]any)
}

type YGFunction

type YGFunction func(YockState) int

type Ycho

type Ycho interface {
	Progress(total int64, r io.Reader) io.Writer
	Eventloop()
	Info(msg string)
	Infof(msg string, v ...any)
	Debug(msg string)
	Debugf(msg string, v ...any)
	Warn(msg string)
	Warnf(msg string, v ...any)
	Fatal(msg string)
	Fatalf(msg string, v ...any)
	Error(msg string)
	Errorf(msg string, v ...any)
	Print(msg string)
}

type YockDB

type YockDB interface {
	Get(k string) lua.LValue
	Put(k string, v lua.LValue)
}

type YockFuncInfo

type YockFuncInfo lua.P

type YockFuns

type YockFuns map[string]YGFunction

type YockJob

type YockJob interface {
	Name() string
	Func() *lua.LFunction
}

type YockLib

type YockLib interface {
	Name() string
	Value() lua.LValue
	SetField(v map[string]any)
	SetFunction(name string, fn lua.LGFunction)
	SetFunctions(v map[string]lua.LGFunction)
	SetYFunction(v map[string]YGFunction)
	SetClosure(v map[string]lua.LGFunction)
	Meta() Table
	SetTable(t Table)
	State() YockState
	SetState(s YockState)
}

type YockLoader

type YockLoader interface {
	// CreateLib returns a new library
	// and overrides old library when it's exist
	CreateLib(name string) YockLib
	// OpenLib opens library to be specified
	// and creates a new library when it isn't exist
	OpenLib(name string) YockLib
	RegLuaFn(LuaFuncs)
	RegYockFn(YockFuns)
	State() YockState
}

type YockMode

type YockMode interface {
	Mode() int32
	SetMode(m int32)
	UnsetMode(m int32)

	Debug() bool
	Strict() bool
}
var Y_MODE YockMode = yockMode(0)

type YockRuntime

type YockRuntime interface {
	// Call to call specify function without arguments
	Call(string) ([]lua.LValue, error)
	// FastCall to call specify function without arguments and not return value
	FastCall(string) error
	// Call to call specify function with arguments
	// CallByParam(string, []lua.LValue) ([]lua.LValue, error)
	// FastCallByParam to call specify function with arguments and not return value
	// FastCallByParam(string, []lua.LValue) error
	// Eval to execute string of script
	Eval(string) error
	// EvalFile to execute file of script
	EvalFile(string) error
	// EvalFunc to execute function
	EvalFunc(lua.LValue, []lua.LValue) ([]lua.LValue, error)
	// FastEvalFunc to execute function and not return value
	FastEvalFunc(lua.LValue, []lua.LValue) error
	// SetGlobalFn to set global function
	SetGlobalFn(map[string]lua.LGFunction)
	// SafeSetGlobalFn to set global function when it isn't exist
	SafeSetGlobalFn(map[string]lua.LGFunction)
	// GetGlobalVar returns global variable
	GetGlobalVar(string) lua.LValue
	// SetGlobalVar to set global variable
	SetGlobalVar(string, lua.LValue)
	// SafeSetGlobalVar to set global variable when variable isn't exist
	SafeSetGlobalVar(string, lua.LValue)
	// RegisterModule to register modules
	// RegisterModule(map[string]lua.LGFunction)
	// UnregisterModule to unregister specify module
	// UnregisterModule(string)
	// LoadModule to immediately load module to be specified
	// LoadModule(string, lua.LGFunction)
	// State returns LState
	State() YockState
	// SetState sets interp
	SetState(l YockState)
	// NewState returns new interp
	NewState() (YockState, context.CancelFunc)
}

YockRuntime is an interface to abstract single and multiple interpreters

type YockScheduler

type YockScheduler interface {
	// yock runtime
	YockLoader
	YockRuntime
	RegYocksFn(funcs YocksFuncs)
	MntYocksFn(lib YockLib, funcs YocksFuncs)

	// yocks field
	EnvVar() EnvVar
	Signal() SignalStream
	Opt() Table
	SetOpt(o Table)
	Env() YockLib

	// yocks goroutines
	Do(f func())

	GetTask(name string) bool
	AppendTask(name string, job YockJob)

	YockDB
}

type YockState

type YockState interface {
	Call(info YockFuncInfo, args ...any) error

	YockStateIs
	YockStateCheck
	YockStatePush

	NewLFunction(f lua.LGFunction) *lua.LFunction
	NewYFunction(f YGFunction) *lua.LFunction
	Exit() int

	Stack(i int) (*lua.Debug, bool)
	Stacktrace() string

	LState() *lua.LState
	Argc() int
	PopAll()
	Clone() YockState
}

type YockStateCheck

type YockStateCheck interface {
	CheckTable(n int) Table
	CheckString(n int) string
	CheckRune(n int) rune
	CheckNumber(n int) lua.LNumber
	CheckInt(n int) int
	CheckBool(n int) bool
	CheckFunction(n int) *lua.LFunction
	CheckAny(n int) any
	CheckLValue(n int) lua.LValue
	CheckLTable(n int) *lua.LTable
}

type YockStateIs

type YockStateIs interface {
	IsNil(n int) bool
	IsFunction(n int) bool
	IsNumber(n int) bool
	IsBool(n int) bool
	IsTable(n int) bool
	IsString(n int) bool
	IsUserData(n int) bool
	IsThread(n int) bool
	IsChannel(n int) bool
}

type YockStatePush

type YockStatePush interface {
	Throw(err error) YockState
	PushError(err error) YockState
	PushNil() YockState
	Push(v lua.LValue) YockState
	PushNilTable() YockState
	PushString(str string) YockState
	PushBool(b bool) YockState
	PushInt(i int) YockState
	Pusha(val any) YockState
	PushAll(vals ...any) YockState
}

type YockdClientFS

type YockdClientFS interface {
	FileSystemPut(src, dst string) error
	FileSystemGet(src, dst string) error
}

type YockdClientGateway

type YockdClientGateway interface{}

type YockdClientMeta

type YockdClientMeta interface {
	IsPublic() bool
	Name() string
	Info() (string, error)
	Status()
	Close()
}

type YockdClientNet

type YockdClientNet interface {
	Ping() error
	Mark(name, addr string) error
	Dial(form, to *pb.NodeInfo) error
	Call(node, method string, args ...string) (string, error)
	MakeTunnel(name string, ctx context.Context, p Promise, event chan PromiseEvent) error
}

type YockdClientProcess

type YockdClientProcess interface {
	ProcessList() ([]*pb.Process, error)
	ProcessKill(pid int64) error
	ProcessFind(pid int64, cmd string) ([]*pb.Process, error)
	ProcessSpawn(t pb.ProcessSpawnType, spec, cmd string) (int64, error)
}

type YockdClientSignal

type YockdClientSignal interface {
	SignalNotify(sig string) error
	SignalWait(sig string) (bool, error)
	SignalInfo(sig string) (bool, bool, error)
	SignalList() ([]string, error)
	SignalClear(sigs ...string) error
}

type YocksFuncs

type YocksFuncs map[string]YocksFunction

type YocksFunction

type YocksFunction func(yocks YockScheduler, state YockState) int

Directories

Path Synopsis
c
go

Jump to

Keyboard shortcuts

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