ops

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpsYaml     = Type("ops:yaml")
	OpsStarlark = Type("ops:starlark")
)

Variables

View Source
var DefaultModuleLoader = func(thread *starlark.Thread, module string) (dict starlark.StringDict, err error) {
	return starlib.Loader(thread, module)
}

DefaultModuleLoader 默认模块加载

Functions

func AddEventsChannel

func AddEventsChannel(eventsCh chan event.Event) func(o *ExecOpts)

AddEventsChannel 设置事件接收器

func DefaultExecOpts

func DefaultExecOpts(o *ExecOpts)

DefaultExecOpts 默认执行配置

func ExecScript

func ExecScript(ctx context.Context, target *Target, opts ...func(o *ExecOpts)) (err error)

ExecScript 执行脚本

func SetLocals

func SetLocals(locals map[string]interface{}) func(o *ExecOpts)

SetLocals 设置KEY/VAL对

func SetOutputWriter

func SetOutputWriter(w io.Writer) func(o *ExecOpts)

SetOutputWriter 设置输出重定向

func SetSecrets

func SetSecrets(secrets map[string]string) func(o *ExecOpts)

SetSecrets 设置KEY/VAL对

func SetTimeout

func SetTimeout(duration time.Duration) func(o *ExecOpts)

SetTimeout 设置超时

func SleepFn

func SleepFn(t *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

SleepFn implements built-in for sleep.

Types

type ExecOpts

type ExecOpts struct {
	// 是否启用浮点数
	AllowFloat bool
	// 是否启用集合类型
	AllowSet bool
	// 是否启用lamda表达式
	AllowLambda bool
	// 是否启用闭包
	AllowNestedDef bool
	// allow reassignment to top-level names; also, allow if/for/while at top-level
	AllowGlobalReassign bool
	// 密码相关
	Secrets map[string]string
	// 局部变量
	Locals map[string]interface{}
	// output接收
	OutputWriter io.Writer
	// 模块加载方法
	ModuleLoader ModuleLoader
	// 事件转发订阅
	EventsCh chan event.Event
	// 超时
	Timeout time.Duration
}

ExecOpts 设置运行时相关开关

type ModuleLoader

type ModuleLoader func(thread *starlark.Thread, module string) (starlark.StringDict, error)

ModuleLoader 模块加载声明

type Runtime

type Runtime struct {
	sync.Mutex

	EventsCh chan event.Event
	// contains filtered or unexported fields
}

Runtime ops解析引擎运行时

func (*Runtime) GetThread

func (r *Runtime) GetThread() *starlark.Thread

GetThread 获取starlark thread

func (*Runtime) SetThread

func (r *Runtime) SetThread(thread *starlark.Thread)

type Target

type Target struct {
	ScriptPath    string `json:"script_path,omitempty"` // 执行脚本路径
	ScriptContent []byte `json:"file"`                  // 执行的脚本路径或者脚本
	ScritType     Type   `json:"type,omitempty"`        // 执行的类型
}

Target 要执行的目标对象

func NewTarget

func NewTarget(scriptPath string) (*Target, error)

type Type

type Type string

Directories

Path Synopsis
Package event 事件转发基本的生产消费模型
Package event 事件转发基本的生产消费模型
compress/gzip
Package gzip defines gzip encoding & decoding functions
Package gzip defines gzip encoding & decoding functions
encoding/base64
Package base64 defines base64 encoding & decoding functions
Package base64 defines base64 encoding & decoding functions
encoding/csv
Package csv reads comma-separated values files
Package csv reads comma-separated values files
encoding/json
Package json defines utilities for converting Starlark values to/from JSON strings.
Package json defines utilities for converting Starlark values to/from JSON strings.
encoding/yaml
Package yaml implements a yaml parser for the starlark programming dialect
Package yaml implements a yaml parser for the starlark programming dialect
env
fs
hash
Package hash defines hash primitives for starlark.
Package hash defines hash primitives for starlark.
html
Package html defines a jquery-like html selection & iteration functions for HTML documents
Package html defines a jquery-like html selection & iteration functions for HTML documents
http
Package http defines a module for doing http operations in starlark
Package http defines a module for doing http operations in starlark
math
Package math is a Starlark module of math-related functions and constants.
Package math is a Starlark module of math-related functions and constants.
re
Package re defines regular expression functions, it's intended to be a drop-in subset of python's re module for starlark: https://docs.python.org/3/library/re.html
Package re defines regular expression functions, it's intended to be a drop-in subset of python's re module for starlark: https://docs.python.org/3/library/re.html
sh
sys
time
Package time provides time-related constants and functions.
Package time provides time-related constants and functions.
zipfile
Package zipfile reads & parses zip archives
Package zipfile reads & parses zip archives
replacecr
Package replacecr defines a wrapper for replacing solo carriage return characters (\r) with carriage-return + line feed (\r\n)
Package replacecr defines a wrapper for replacing solo carriage return characters (\r) with carriage-return + line feed (\r\n)

Jump to

Keyboard shortcuts

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