Help us shape the future of Go! Take the 2026 Go Developer Survey

expand

package
v0.4.0 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: 5 Imported by: 0

Documentation

Overview

Package expand substitutes variables in Containerfile words the way the Dockerfile reference's "Environment replacement" section specifies, with the grammar of BuildKit's frontend/dockerfile/shell lexer: single and double quotes, the escape token, $name and ${name}, and the modifiers ${name:-word} ${name-word} ${name:+word} ${name+word} ${name?word} ${name:?word} ${name#pattern} ${name##pattern} ${name%pattern} ${name%%pattern} ${name/pattern/repl} ${name//pattern/repl}.

Nothing is ever executed: there is no command substitution, no arithmetic, no globbing of the file system. A value is inserted as data and never re-scanned, so a variable cannot inject syntax. The output and the nesting of ${...} are bounded.

Index

Constants

View Source
const (
	// MaxOutput is the largest result of one word, in bytes.
	MaxOutput = 1 << 20
	// MaxDepth is the deepest nesting of ${...}.
	MaxDepth = 32
)

Limits of one expansion.

Variables

View Source
var ErrTooLong = errors.New("expansion exceeds 1 MiB")

ErrTooLong reports an expansion beyond MaxOutput.

Functions

This section is empty.

Types

type Env

type Env interface {
	Get(name string) (string, bool)
}

Env answers variable lookups.

type Lexer

type Lexer struct {
	Escape rune
}

Lexer expands words with an escape token ('\\' or '`').

func (Lexer) Word

func (l Lexer) Word(s string, env Env) (string, error)

Word expands s and returns it as one string (quotes removed, spaces kept).

func (Lexer) Words

func (l Lexer) Words(s string, env Env) ([]string, error)

Words expands s and splits the result into words, after substitution, honouring quotes: an unquoted value that holds spaces becomes several words.

type Map

type Map map[string]string

Map is an Env over a map.

func (Map) Get

func (m Map) Get(name string) (string, bool)

Get implements Env.

Jump to

Keyboard shortcuts

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