blobmunge

package module
v0.0.0-...-eaaa502 Latest Latest
Warning

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

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

README

blobmunge

blobmunge provides helper functions for using Redpanda Connect's Bloblang mapping language to munge structured data. blobmunge uses MapStructure/v2 to decode data prior to processing.

Features

  • blobmunge.New() creates a new BlobMunger from a Bloblang mapping.
  • BlobMunger.UpdateMapping() parses bloblang and returns an executor to be applied to input data.
  • BlobMunger.ApplyBloblangMapping() executes a bloblang mapping on structured input data.
  • InputMap() converts a structured input (json string or []byte, Go data type) into a map[string]any.

🚀 Install

Using blobmunge is easy. First, use go get to install the latest version of the library.

go get -u github.com/loicalleyne/blobmunge@latest

💡 Usage

You can import blobmunge using:

import "github.com/loicalleyne/blobmunge"

Create a new BlobMunger with a Bloblang rule, then apply it to some data.

var jsonS1 string = `{"id":1234,"dev":"12345ert"}`
var bloblString string = `root.id = this.id\nroot.device = this.dev`
u, _ := blobmunge.New(bloblString)
b, _ := u.ApplyBloblangMapping(jsonS1)
fmt.Printf(string(b))
// {"device":"12345ert","id":1234}

💫 Show your support

Give a ⭐️ if this project helped you!

License

blobmunge is released under the Apache 2.0 license. See LICENCE.txt

Documentation

Overview

package blobmunge provides helper functions for using Redpanda Connect's bloblang mapping language to munge structured data. blobmunge uses MapStructure/v2 to decode data prior to processing. MapStructure/v2: github.com/go-viper/mapstructure/v2

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUndefinedInput   = errors.New("nil input")
	ErrInvalidInput     = errors.New("invalid input")
	ErrUndefinedMapping = errors.New("nil mapping")
)

Functions

func InputMap

func InputMap(a any) (map[string]any, error)

InputMap takes structured input data and attempts to decode it to map[string]any. Input data can be json in string or []byte, or any other Go data type which can be handled by MapStructure/v2. MapStructure/v2: github.com/go-viper/mapstructure/v2

Types

type BlobMunger

type BlobMunger struct {
	// contains filtered or unexported fields
}

BlobMunger

func New

func New(bloblangMapping string) (*BlobMunger, error)

New returns new BlobMunger or an error if mapping cannot be parsed.

func (*BlobMunger) ApplyBloblangMapping

func (b *BlobMunger) ApplyBloblangMapping(input any) ([]byte, error)

ApplyBloblangMapping executes a bloblang mapping on structured input data.

func (*BlobMunger) UpdateMapping

func (b *BlobMunger) UpdateMapping(bloblangMapping string) error

UpdateMapping method attempts to update the mapping rule, if an error is encountered it leaves the existing mapping in place.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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