Documentation
¶
Index ¶
- Constants
- Variables
- func BindGHTTPRouter(ctx context.Context, group *ghttp.RouterGroup, lc LifeCycle, ...) (err error)
- func ExecuteNode(ctx context.Context, root *Node, nlc NodeLifeCycle, input map[string]any, ...) (output map[string]any, err error)
- func SetMapValue(m any, index string, v any) any
- type GoFrameHTTPInputHandler
- type LifeCycle
- type Meta
- type Node
- type NodeLifeCycle
- type Parameter
- type ParameterValidate
- type Proto
- type Script
- type ScriptExecuteResult
Constants ¶
View Source
const ( FuncNameSetInput = "set_input" FuncNameGetInput = "get_input" FuncNameSetResult = "set_result" FuncNameGetResult = "get_result" FuncNameNewMap = "new_map" FuncNameSetMapValue = "set_map_value" FuncNameLogInfo = "info" FuncNameLogWarning = "warning" FuncNameLogError = "error" )
View Source
const (
CtxKeyNodeName = "__node_name"
)
Variables ¶
View Source
var ( ErrInvalidParameter = errors.New("invalid parameter") ErrNodeExecuteFailed = errors.New("node execute failed") )
Functions ¶
func BindGHTTPRouter ¶
func ExecuteNode ¶
Types ¶
type GoFrameHTTPInputHandler ¶
type GoFrameHTTPInputHandler struct{}
func (GoFrameHTTPInputHandler) HandleInput ¶
type LifeCycle ¶
type LifeCycle interface {
NodeLifeCycle
// HandleInput defines how to handle input
HandleInput(ctx context.Context, proto *Proto) (input map[string]any, err error)
// HandleOutput defines how to handle output
HandleOutput(ctx context.Context, proto *Proto, raw map[string]any) (out any, err error)
}
LifeCycle interface
type Node ¶
type Node struct {
// Name of node, output will be overwritten if
// using same name.
Name string `json:"name"`
// Meta data
Meta Meta `json:"meta"`
// Must execute success flag.
// checks NodeLifeCycle.Execute return error
Must bool `json:"must"`
// Children nodes
Children []*Node `json:"children"`
// InputFilter of node, supported alias usage,
// e.g. "aaa as bbb" empty means no filter,
// all input will be passed
InputFilter []string `json:"input_filter" yaml:"input_filter"`
// Script in go template syntax
Script Script `json:"script"`
// contains filtered or unexported fields
}
Node of procedure, defines call flow and behavior. nodes will be executed in level order synchronously or asynchronously by NodeHandleFunc within input.
type NodeLifeCycle ¶
type NodeLifeCycle interface {
// BeforeExecute defines aspect before execute
// input is copy of ExecuteNode input and filtered.
BeforeExecute(ctx context.Context, node *Node, input map[string]any) (err error)
// Execute defines how to execute a node.
// input is copy of ExecuteNode input and
// filtered. after execute, output will be
// saved to ExecuteNode output in key node.Name
Execute(ctx context.Context, node *Node, input map[string]any) (output any, err error)
// AfterExecute defines aspect after execute.
AfterExecute(ctx context.Context, node *Node, output any, err error)
// BeforeScript defines parameters to build the
// template.Template, returns the template.FuncMap
// and the template execute input.
// this method called after AfterExecute only if
// node.Script is not empty.
BeforeScript(ctx context.Context, node *Node, input map[string]any, output any) (fm template.FuncMap)
}
NodeLifeCycle defines node life cycle
type Parameter ¶
type Parameter struct {
// Name of parameter
Name string `json:"name"`
// Validate validator define of parameter
Validate *ParameterValidate `json:"validate,omitempty"`
// Meta of parameter
Meta Meta `json:"meta"`
}
Parameter defines parameter
type ParameterValidate ¶
type ParameterValidate struct {
// validator rule
// e.g. "required|length:6,16|same:password2"
Rule string `json:"rule"`
// error message accept map or string
// e.g. "message": "xxx"
// e.g. "message": {"required": "xxx", "same": "xxx"}
Message any `json:"message"`
}
ParameterValidate defines parameter validate rules and error messages. see https://goframe.org/docs/core/gvalid
type Proto ¶
type Proto struct {
// LifeCycle of proto
LifeCycle `json:"-" yaml:"-"`
// Name of proto
Name string `json:"name"`
// Meta data
Meta Meta `json:"meta"`
// Parameters define
Parameters []*Parameter `json:"parameters"`
// Node of procedure
Node *Node `json:"node"`
// Async is a flag that indicates whether
// the node is executed asynchronously
Async bool `json:"async"`
// Script in go template syntax
Script Script `json:"script"`
// contains filtered or unexported fields
}
Proto of procedure
func NewProtoFromYaml ¶
func (*Proto) BuildValidator ¶
Click to show internal directories.
Click to hide internal directories.