interp

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package interp implements the Compose Specification's variable interpolation: `$VAR`, `${VAR}`, `${VAR:-default}`, `${VAR-default}`, `${VAR:?error}`, `${VAR?error}`, and the reference implementation's `${VAR:+replacement}` and `${VAR+replacement}`; `$$` is a literal `$`. Defaults and messages are interpolated in turn (nesting).

Nothing is ever executed: a value is looked up in a map, never in a shell. Output and nesting are bounded (the input is untrusted).

Index

Constants

View Source
const MaxNesting = 32

MaxNesting bounds `${A:-${B:-...}}` nesting.

Variables

View Source
var ErrTooLarge = errors.New("interpolation result too large")

ErrTooLarge is returned when a result outgrows its budget.

Functions

This section is empty.

Types

type Interpolator

type Interpolator struct {
	Lookup Lookup
	// Budget is how many bytes all results may total (0: 64 MiB); MaxString
	// bounds one result (0: 1 MiB).
	Budget, MaxString int
	// Unset, when not nil, is told of each variable used without a value
	// and without a default (it then reads as "").
	Unset func(name string)
	// contains filtered or unexported fields
}

Interpolator substitutes variables, within a byte budget shared by every call (a file's values together, not each one alone).

func (*Interpolator) Substitute

func (in *Interpolator) Substitute(s string) (string, error)

Substitute interpolates s.

type Lookup

type Lookup func(name string) (string, bool)

Lookup returns a variable's value and whether it is set.

type MissingError

type MissingError struct {
	Name, Message string
}

MissingError is a `${VAR:?msg}` / `${VAR?msg}` whose variable is unset (or empty, for `:?`).

func (*MissingError) Error

func (e *MissingError) Error() string

Jump to

Keyboard shortcuts

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