transform

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 8 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

Jump to

Keyboard shortcuts

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