transform

package
v1.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 43 Imported by: 0

README

transform

Contains interfaces and methods for transforming data.

Documentation

Overview

Package transform provides functions for transforming data.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(ctx context.Context, tf []Transformer, mess ...*message.Message) ([]*message.Message, error)

Types

type Transformer

type Transformer interface {
	Transform(context.Context, *message.Message) ([]*message.Message, error)
}

Transformer is the interface implemented by all transforms and provides the ability to transform data.

Example
package main

import (
	"context"
	"fmt"

	"github.com/brexhq/substation/config"
	"github.com/brexhq/substation/message"
	"github.com/brexhq/substation/transform"
)

func main() {
	ctx := context.TODO()

	// Copies the value of key "a" into key "b".
	cfg := config.Config{
		Type: "object_copy",
		Settings: map[string]interface{}{
			"object": map[string]interface{}{
				"key":     "a",
				"set_key": "b",
			},
		},
	}

	tf, err := transform.New(ctx, cfg)
	if err != nil {
		// handle err
		panic(err)
	}

	// Transformer is applied to a message.
	msg := message.New().SetData([]byte(`{"a":1}`))
	results, err := tf.Transform(ctx, msg)
	if err != nil {
		// handle err
		panic(err)
	}

	for _, c := range results {
		fmt.Println(string(c.Data()))
	}

}
Output:

{"a":1,"b":1}

func New

func New(ctx context.Context, cfg config.Config) (Transformer, error)

New returns a configured Transformer.

Source Files

Jump to

Keyboard shortcuts

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