12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package test_node
- import (
- "fmt"
- "git.sxidc.com/go-tools/utils/pipeline/component"
- "git.sxidc.com/go-tools/utils/pipeline/component/flow"
- "github.com/mitchellh/mapstructure"
- "github.com/pkg/errors"
- )
- const (
- TypePrintln = "println"
- )
- type PrintlnRunParams struct {
- Content string `mapstructure:"content"`
- }
- type PrintlnNode struct {
- component.BaseComponent
- }
- func (n *PrintlnNode) Run(globalRunParams *component.GlobalRunParams, dynamicParams map[string]any) (any, error) {
- return n.OnRun(globalRunParams, dynamicParams,
- func(globalRunParams *component.GlobalRunParams, dynamicParams map[string]any) (any, error) {
- fmt.Println("----------PRINTLN----------")
- fmt.Println("Global Params:")
- for key, value := range globalRunParams.CustomRunParams {
- fmt.Println(key+":", value)
- }
- rangeIndex, ok := dynamicParams[flow.RangeIndex]
- if ok {
- fmt.Println("Range Params Index:", rangeIndex)
- }
- rangeOnceValue, ok := dynamicParams[flow.RangeOnceValue]
- if ok {
- fmt.Println("Range Params:", rangeOnceValue)
- }
- biLeftParams, ok := dynamicParams[flow.BiLeft]
- if ok {
- fmt.Println("Bi Left Params:", biLeftParams)
- }
- biRightParams, ok := dynamicParams[flow.BiRight]
- if ok {
- fmt.Println("Bi Right Params:", biRightParams)
- }
- params := new(PrintlnRunParams)
- err := mapstructure.Decode(dynamicParams, params)
- if err != nil {
- return nil, errors.New(TypePrintln + "节点运行时参数Decode失败: " + err.Error())
- }
- fmt.Println(params.Content)
- fmt.Println("----------PRINTLN----------")
- return nil, nil
- })
- }
- type PrintlnBuilder struct{}
- func (builder *PrintlnBuilder) ProductType() string {
- return TypePrintln
- }
- func (builder *PrintlnBuilder) Build(name string, _ map[string]any, runParams map[string]any) (component.Component, error) {
- return &PrintlnNode{
- BaseComponent: *component.NewBaseComponent(TypePrintln, name, runParams),
- }, nil
- }
|