template

package
v0.0.0-...-1fa5987 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package template implements string substitution in the style of Python's string.Template library as extended by Docker Compose.

References: - https://github.com/docker/compose/blob/4a51af09d6cdb9407a6717334333900327bc9302/compose/config/interpolation.py - https://docs.python.org/3/library/string.html#string.Template - https://github.com/compose-spec/compose-spec/blob/b369fe5e02d80b619d14974cd1e64e7eea1b2345/spec.md#interpolation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Substitute

func Substitute(template Template, env Environment) (string, error)

Types

type Environment

type Environment interface {
	Lookup(*Variable) (string, error)
}
var ErrEnvironment Environment = errEnvironment{}

type Literal

type Literal struct {
	Value string
}

func (*Literal) Substitute

func (lit *Literal) Substitute(w io.Writer, env Environment) error

type MapEnvironment

type MapEnvironment map[string]string

func (MapEnvironment) Lookup

func (env MapEnvironment) Lookup(v *Variable) (substitution string, err error)

type Sequence

type Sequence struct {
	Elements []Template
}

func (*Sequence) Substitute

func (seq *Sequence) Substitute(w io.Writer, env Environment) error

type Template

type Template interface {
	Substitute(w io.Writer, env Environment) error
}

func Parse

func Parse(s string) (Template, error)

type Variable

type Variable struct {
	Name           string
	Braces         bool
	Separator      string
	DefaultOrError string
}

func (*Variable) Substitute

func (v *Variable) Substitute(w io.Writer, env Environment) error

Jump to

Keyboard shortcuts

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