text

package
v3.54.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: MIT Imports: 11 Imported by: 4

Documentation

Overview

Package text includes utilities for working with text that might contain variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsEnvVariables

func ContainsEnvVariables(inBytes []byte) bool

ContainsEnvVariables returns true if inBytes contains environment variable replace patterns.

func ContainsFunctionVariables

func ContainsFunctionVariables(inBytes []byte) bool

ContainsFunctionVariables returns true if inBytes contains function variable replace patterns.

func ReplaceEnvVariables

func ReplaceEnvVariables(inBytes []byte) []byte

ReplaceEnvVariables will search a blob of data for the pattern `${FOO:bar}`, where `FOO` is an environment variable name and `bar` is a default value. The `bar` section (including the colon) can be left out if there is no appropriate default value for the field.

For each aforementioned pattern found in the blob the contents of the respective environment variable will be read and will replace the pattern. If the environment variable is empty or does not exist then either the default value is used or the field will be left empty.

func ReplaceFunctionVariables

func ReplaceFunctionVariables(msg Message, inBytes []byte) []byte

ReplaceFunctionVariables will search a blob of data for the pattern `${!foo}`, where `foo` is a function name.

For each aforementioned pattern found in the blob the contents of the respective function will be run and will replace the pattern.

Some functions are able to extract contents and metadata from a message, and so a message must be supplied.

func ReplaceFunctionVariablesEscaped

func ReplaceFunctionVariablesEscaped(msg Message, inBytes []byte) []byte

ReplaceFunctionVariablesEscaped will search a blob of data for the pattern `${!foo}`, where `foo` is a function name.

For each aforementioned pattern found in the blob the contents of the respective function will be run and will replace the pattern.

The contents of the swapped pattern is escaped such that it can be safely injected within the contents of a JSON object.

Some functions are able to extract contents and metadata from a message, and so a message must be supplied.

func ReplaceFunctionVariablesEscapedFor added in v3.12.0

func ReplaceFunctionVariablesEscapedFor(msg Message, index int, inBytes []byte) []byte

ReplaceFunctionVariablesEscapedFor will search a blob of data for the pattern `${!foo}`, where `foo` is a function name.

For each aforementioned pattern found in the blob the contents of the respective function will be run and will replace the pattern.

The contents of the swapped pattern is escaped such that it can be safely injected within the contents of a JSON object.

Some functions are able to extract contents and metadata from a message, and so a message must be supplied along with the specific index of the message part that this function should be resolved for.

func ReplaceFunctionVariablesFor added in v3.12.0

func ReplaceFunctionVariablesFor(msg Message, index int, inBytes []byte) []byte

ReplaceFunctionVariablesFor will search a blob of data for the pattern `${!foo}`, where `foo` is a function name.

For each aforementioned pattern found in the blob the contents of the respective function will be run and will replace the pattern.

Some functions are able to extract contents and metadata from a message, and so a message must be supplied along with the specific index of the message part that this function should be resolved for.

Types

type InterpolatedBytes

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

InterpolatedBytes holds a byte slice that potentially has interpolation functions. Each time Get is called any functions are replaced with their evaluated results in the byte slice.

func NewInterpolatedBytes

func NewInterpolatedBytes(v []byte) *InterpolatedBytes

NewInterpolatedBytes returns a type that evaluates function interpolations on a provided byte slice each time Get is called.

func (*InterpolatedBytes) Get

func (i *InterpolatedBytes) Get(msg Message) []byte

Get evaluates functions within the byte slice and returns the result.

func (*InterpolatedBytes) GetFor added in v3.12.0

func (i *InterpolatedBytes) GetFor(msg Message, index int) []byte

GetFor evaluates functions within the byte slice and returns the result, evaluated for a specific message part of the message.

type InterpolatedString

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

InterpolatedString holds a string that potentially has interpolation functions. Each time Get is called any functions are replaced with their evaluated results in the string.

func NewInterpolatedString

func NewInterpolatedString(str string) *InterpolatedString

NewInterpolatedString returns a type that evaluates function interpolations on a provided string each time Get is called.

func (*InterpolatedString) Get

func (i *InterpolatedString) Get(msg Message) string

Get evaluates functions within the original string and returns the result.

func (*InterpolatedString) GetFor added in v3.12.0

func (i *InterpolatedString) GetFor(msg Message, index int) string

GetFor evaluates functions within the original string and returns the result, evaluated for a specific message part of the message.

type Message

type Message interface {
	Get(p int) types.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.

Jump to

Keyboard shortcuts

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