field

package
v4.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package field implements a bloblang interpolation function templating syntax used in some dynamic fields within Benthos. Only the query (right-hand side) part of the bloblang spec is supported within interpolation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expression

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

Expression represents a Benthos dynamic field expression, used to configure string fields where the contents should change based on the contents of messages and other factors.

Each function here resolves the expression for a particular message of a batch, this is why an index is expected.

func NewExpression

func NewExpression(resolvers ...Resolver) *Expression

NewExpression creates a field expression from a slice of resolvers.

func (*Expression) Bytes

func (e *Expression) Bytes(index int, msg Message) ([]byte, error)

Bytes returns a byte slice representing the expression resolved for a message of a batch.

func (*Expression) NumDynamicExpressions

func (e *Expression) NumDynamicExpressions() int

NumDynamicExpressions returns the number of dynamic interpolation functions within the expression.

func (*Expression) String

func (e *Expression) String(index int, msg Message) (string, error)

String returns a string representing the expression resolved for a message of a batch.

type Message

type Message interface {
	Get(p int) *message.Part
	Len() int
}

Message is an interface type to be given to a function interpolator, it allows the function to resolve fields and metadata from a message.

type QueryResolver

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

QueryResolver executes a query and returns a string representation of the result.

func NewQueryResolver

func NewQueryResolver(fn query.Function) *QueryResolver

NewQueryResolver creates a field query resolver that returns the result of a query function.

func (QueryResolver) ResolveBytes

func (q QueryResolver) ResolveBytes(index int, msg Message, escaped bool) ([]byte, error)

ResolveBytes returns a byte slice.

func (QueryResolver) ResolveString

func (q QueryResolver) ResolveString(index int, msg Message, escaped bool) (string, error)

ResolveString returns a string.

type Resolver

type Resolver interface {
	ResolveString(index int, msg Message, escaped bool) (string, error)
	ResolveBytes(index int, msg Message, escaped bool) ([]byte, error)
}

Resolver is an interface for resolving a string containing Bloblang function interpolations into either a string or bytes.

type StaticResolver

type StaticResolver string

StaticResolver is a Resolver implementation that simply returns a static string.

func (StaticResolver) ResolveBytes

func (s StaticResolver) ResolveBytes(index int, msg Message, escaped bool) ([]byte, error)

ResolveBytes returns a byte slice.

func (StaticResolver) ResolveString

func (s StaticResolver) ResolveString(index int, msg Message, escaped bool) (string, error)

ResolveString returns a string.

Jump to

Keyboard shortcuts

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