println.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package test_node
  2. import (
  3. "errors"
  4. "fmt"
  5. "git.sxidc.com/go-tools/utils/pipeline/component"
  6. "git.sxidc.com/go-tools/utils/pipeline/component/flow"
  7. "github.com/mitchellh/mapstructure"
  8. )
  9. const (
  10. TypePrintln = "println"
  11. )
  12. type PrintlnRunParams struct {
  13. Content string `mapstructure:"content"`
  14. }
  15. type PrintlnNode struct {
  16. component.BaseComponent
  17. }
  18. func (n *PrintlnNode) Run(globalRunParams *component.GlobalRunParams, dynamicParams map[string]any) (any, error) {
  19. return n.OnRun(globalRunParams, dynamicParams,
  20. func(globalRunParams *component.GlobalRunParams, dynamicParams map[string]any) (any, error) {
  21. fmt.Println("----------PRINTLN----------")
  22. fmt.Println("Global Params:")
  23. for key, value := range globalRunParams.CustomRunParams {
  24. fmt.Println(key+":", value)
  25. }
  26. rangeIndex, ok := dynamicParams[flow.RangeIndex]
  27. if ok {
  28. fmt.Println("Range Params Index:", rangeIndex)
  29. }
  30. rangeOnceValue, ok := dynamicParams[flow.RangeOnceValue]
  31. if ok {
  32. fmt.Println("Range Params:", rangeOnceValue)
  33. }
  34. biLeftParams, ok := dynamicParams[flow.BiLeft]
  35. if ok {
  36. fmt.Println("Bi Left Params:", biLeftParams)
  37. }
  38. biRightParams, ok := dynamicParams[flow.BiRight]
  39. if ok {
  40. fmt.Println("Bi Right Params:", biRightParams)
  41. }
  42. params := new(PrintlnRunParams)
  43. err := mapstructure.Decode(dynamicParams, params)
  44. if err != nil {
  45. return nil, errors.New(TypePrintln + "节点运行时参数Decode失败: " + err.Error())
  46. }
  47. fmt.Println(params.Content)
  48. fmt.Println("----------PRINTLN----------")
  49. return nil, nil
  50. })
  51. }
  52. type PrintlnBuilder struct{}
  53. func (builder *PrintlnBuilder) ProductType() string {
  54. return TypePrintln
  55. }
  56. func (builder *PrintlnBuilder) Build(name string, _ map[string]any, runParams map[string]any) (component.Component, error) {
  57. return &PrintlnNode{
  58. BaseComponent: *component.NewBaseComponent(TypePrintln, name, runParams),
  59. }, nil
  60. }