engine

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncMap

func FuncMap(secretReaders []SecretReaderFunc) template.FuncMap

FuncMap returns a mapping of all of the functions that Temmplate has.

func Render

func Render(input string, data interface{}) (content string, err error)

Render compile and assemble attribute template to merge with values.

func RenderContext

func RenderContext(templateContext Context, input string) (string, error)

RenderContext compile and assemble attribute template to merge with values.

func RenderContextWithData

func RenderContextWithData(templateContext Context, input string, data interface{}) (content string, err error)

RenderContextWithData compile and assemble attribute template to merge with values.

func SecretReaders

func SecretReaders(secretReaders []SecretReaderFunc) func(string) (map[string]interface{}, error)

SecretReaders uses given secret reader funcs to resolve secret path.

Types

type Context

type Context interface {
	Name() string
	StrictMode() bool
	Delims() (string, string)
	SecretReaders() []SecretReaderFunc
	Values() Values
	Files() Files
}

Context describes engine rendering context contract.

func NewContext

func NewContext(opts ...ContextOption) Context

NewContext returns a template rendering context.

type ContextOption

type ContextOption func(*context)

ContextOption defines context functional builder function

func WithDelims

func WithDelims(left, right string) ContextOption

WithDelims defines used delimiters for rendering engine.

func WithFiles

func WithFiles(files Files) ContextOption

WithFiles defines file collection.

func WithName

func WithName(value string) ContextOption

WithName sets the template name.

func WithSecretReaders

func WithSecretReaders(values ...SecretReaderFunc) ContextOption

WithSecretReaders defines secret resolver functions used by `secret` template function.

func WithStrictMode

func WithStrictMode(value bool) ContextOption

WithStrictMode enable or disable strict rendering mode.

func WithValues

func WithValues(values Values) ContextOption

WithValues defines template values injected via CLI.

type ErrNoTable

type ErrNoTable struct {
	Key string
}

ErrNoTable indicates that a chart does not have a matching table.

func (ErrNoTable) Error

func (e ErrNoTable) Error() string

type ErrNoValue

type ErrNoValue struct {
	Key string
}

ErrNoValue indicates that Values does not contain a key with a value

func (ErrNoValue) Error

func (e ErrNoValue) Error() string

type Files

type Files map[string][]byte

Files is a map of files that can be accessed from a template.

func NewFiles

func NewFiles(from []*files.BufferedFile) Files

NewFiles returns an engine file collection from file loader.

func (Files) AsConfig

func (f Files) AsConfig() map[string]string

AsConfig returns a Files group and flattens it to a YAML map suitable for including in the 'data' section of a Kubernetes ConfigMap definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.

The output will not be indented, so you will want to pipe this to the 'indent' template function.

data:

{{ .Files.Glob("config/**").AsConfig() | toYaml | indent 4 }}

func (Files) AsSecrets

func (f Files) AsSecrets() map[string]string

AsSecrets returns the base64-encoded value of a Files object suitable for including in the 'data' section of a Kubernetes Secret definition. Duplicate keys will be overwritten, so be aware that your file names (regardless of path) should be unique.

The output will not be indented, so you will want to pipe this to the 'indent' template function.

data:

{{ .Files.Glob("secrets/*").AsSecrets() | toYaml }}

func (Files) Get

func (f Files) Get(name string) string

Get returns a string representation of the given file.

Fetch the contents of a file as a string. It is designed to be called in a template.

{{.Files.Get "foo"}}

func (Files) GetBytes

func (f Files) GetBytes(name string) []byte

GetBytes gets a file by path.

The returned data is raw. In a template context, this is identical to calling {{index .Files $path}}.

This is intended to be accessed from within a template, so a missed key returns an empty []byte.

func (Files) Glob

func (f Files) Glob(pattern string) Files

Glob takes a glob pattern and returns another files object only containing matched files.

This is designed to be called from a template.

{{ range $name, $content := .Files.Glob("foo/**") }} {{ $name }}: | {{ .Files.Get($name) | indent 4 }}{{ end }}

func (Files) Lines

func (f Files) Lines(filePath string) []string

Lines returns each line of a named file (split by "\n") as a slice, so it can be ranged over in your templates.

This is designed to be called from a template.

{{ range .Files.Lines "foo/bar.html" }} {{ . }}{{ end }}

type SecretReaderFunc

type SecretReaderFunc func(path string) (map[string]interface{}, error)

SecretReaderFunc is a function to retrieve a secret from a given path.

type Values

type Values map[string]interface{}

Values represents a collection of template values.

func ReadValues

func ReadValues(r io.Reader) (vals Values, err error)

ReadValues will parse YAML byte data into a Values.

func (Values) AsMap

func (v Values) AsMap() map[string]interface{}

AsMap is a utility function for converting Values to a map[string]interface{}.

It protects against nil map panics.

func (Values) Encode

func (v Values) Encode(w io.Writer) error

Encode writes serialized Values information to the given io.Writer.

func (Values) PathValue

func (v Values) PathValue(path string) (interface{}, error)

PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods. Given the following YAML data the value at path "chapter.one.title" is "Loomings".

chapter:
  one:
    title: "Loomings"

func (Values) Table

func (v Values) Table(name string) (Values, error)

Table gets a table (YAML subsection) from a Values object.

The table is returned as a Values.

Compound table names may be specified with dots:

foo.bar

The above will be evaluated as "The table bar inside the table foo".

An ErrNoTable is returned if the table does not exist.

func (Values) YAML

func (v Values) YAML() (string, error)

YAML encodes the Values into a YAML string.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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