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 ¶
const MaxNesting = 32
MaxNesting bounds `${A:-${B:-...}}` nesting.
Variables ¶
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 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