interpolation

package
v27.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const PathMatchAll = "*"

PathMatchAll is a token used as part of a Path to match any key at that level in the nested structure

View Source
const PathMatchList = "[]"

PathMatchList is a token used as part of a Path to match items in a list

Variables

This section is empty.

Functions

func Interpolate

func Interpolate(config map[string]any, opts Options) (map[string]any, error)

Interpolate replaces variables in a string with the values from a mapping

Types

type Cast

type Cast func(value string) (any, error)

Cast a value to a new type, or return an error if the value can't be cast

type LookupValue

type LookupValue func(key string) (string, bool)

LookupValue is a function which maps from variable names to values. Returns the value as a string and a bool indicating whether the value is present, to distinguish between an empty string and the absence of a value.

type Options

type Options struct {
	// LookupValue from a key
	LookupValue LookupValue
	// TypeCastMapping maps key paths to functions to cast to a type
	TypeCastMapping map[Path]Cast
	// Substitution function to use
	Substitute func(string, template.Mapping) (string, error)
}

Options supported by Interpolate

type Path

type Path string

Path is a dotted path of keys to a value in a nested mapping structure. A * section in a path will match any key in the mapping structure.

func NewPath

func NewPath(items ...string) Path

NewPath returns a new Path

func (Path) Next

func (p Path) Next(part string) Path

Next returns a new path by append part to the current path

Jump to

Keyboard shortcuts

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