transform

package
v0.0.0-...-be2e216 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

transform

Transform messages.

How to customize components

Implement the types.Node interface. Example of a custom component:

// Define the Node component
// UpperNode A plugin that converts the message data to uppercase
type UpperNode struct{}

func (n *UpperNode) Type() string {
    return "test/upper"
}

func (n *UpperNode) New() types.Node {
    return &UpperNode{}
}

func (n *UpperNode) Init(ruleConfig types.Config, configuration types.Configuration) error {
    // Do some initialization work
    return nil
}

// Process the message
func (n *UpperNode) OnMsg(ctx types.RuleContext, msg types.RuleMsg) {
    msg.Data = strings.ToUpper(msg.Data)
    // Send the modified message to the next node
    ctx.TellSuccess(msg)
    return nil
}

func (n *UpperNode) Destroy() {
    // Do some cleanup work
}

Usage

Register the component to the RuleGo default registry:

rulego.Registry.Register(&MyNode{})

Then use your component in the rule chain DSL file:

{
  "ruleChain": {
    "id": "rue01",
    "name": "Test rule chain
  },
  "metadata": {
    "nodes": [
      {
        "id": "s1",
        "type": "test/upper",
        "name": "Name",
        "debugMode": true,
        "configuration": {
          "field1": "Configuration parameters defined by the component",
          "....": "..."
        }
      }
    ],
    "connections": [
      {
        "fromId": "s1",
        "toId": "Connect to the next component ID",
        "type": "The connection relationship with the component"
      }
    ]
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LuaTransform

type LuaTransform struct {
	Config LuaTransformConfiguration
	// contains filtered or unexported fields
}

LuaTransform is a component that transforms messages based on Lua scripts

func (*LuaTransform) Destroy

func (x *LuaTransform) Destroy()

Destroy releases the resources of the component

func (*LuaTransform) Init

func (x *LuaTransform) Init(ruleConfig types.Config, configuration types.Configuration) error

Init initializes the component

func (*LuaTransform) New

func (x *LuaTransform) New() types.Node

New creates a new instance of LuaFilter

func (*LuaTransform) OnMsg

func (x *LuaTransform) OnMsg(ctx types.RuleContext, msg types.RuleMsg)

OnMsg handles the message

func (*LuaTransform) Type

func (x *LuaTransform) Type() string

Type returns the type of the component

type LuaTransformConfiguration

type LuaTransformConfiguration struct {
	//Script configures the function body content or the script file path with `.lua` as the suffix
	//Only need to provide the function body content, if it is a file path, then need to provide the complete script function:
	//function Transform(msg, metadata, msgType) ${Script} \n end
	//return msg, metadata, msgType
	//The parameter msg, if the data type of msg is JSON, then it will be converted to the Lua table type before calling the function
	Script string
}

LuaTransformConfiguration node configuration

type RowData

type RowData map[string]interface{}

RowData 表示一行数据

type Xlsx2JsonTransform

type Xlsx2JsonTransform struct {
	Config Xlsx2JsonTransformConfiguration
}

func (*Xlsx2JsonTransform) Close

func (x *Xlsx2JsonTransform) Close() error

func (*Xlsx2JsonTransform) Destroy

func (x *Xlsx2JsonTransform) Destroy()

Destroy 销毁,做一些资源释放操作

func (*Xlsx2JsonTransform) Init

func (x *Xlsx2JsonTransform) Init(ruleConfig types.Config, configuration types.Configuration) error

Init 组件初始化,一般做一些组件参数配置或者客户端初始化操作 规则链里的规则节点初始化会调用一次

func (*Xlsx2JsonTransform) New

func (x *Xlsx2JsonTransform) New() types.Node

New 创建一个组件新实例 每个规则链的规则节点都会创建一个新的实例,数据是隔离的

func (*Xlsx2JsonTransform) OnMsg

func (x *Xlsx2JsonTransform) OnMsg(ctx types.RuleContext, msg types.RuleMsg)

OnMsg 处理消息,并控制流向子节点的关系。每条流入组件的数据会经过该方法处理 ctx:规则引擎处理消息上下文 msg:消息

func (*Xlsx2JsonTransform) Type

func (x *Xlsx2JsonTransform) Type() string

Type 组件类型,类型不能重复。 用于规则链,node.type配置,初始化对应的组件 建议使用`/`区分命名空间,防止冲突。例如:x/httpClient

type Xlsx2JsonTransformConfiguration

type Xlsx2JsonTransformConfiguration struct {
	// 文件下载链接
	DownLoadUrl string
}

Xlsx2JsonTransformConfiguration node configuration

Jump to

Keyboard shortcuts

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