Version: v0.0.0-...-5aeb2b0 Latest Latest

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

Go to latest
Published: Jul 26, 2021 License: Apache-2.0 Imports: 5 Imported by: 6



Package vars implements a registry of ${var} placeholders.

They can be used in config validation rule patterns and config set names and paths in place of a not-yet-known values.



This section is empty.


This section is empty.


This section is empty.


type VarSet

type VarSet struct {
	// contains filtered or unexported fields

VarSet holds a registry ${var} -> callback that extracts it from a context.

It is used by the config client to render config validation patterns like "services/${appid}". By using placeholder vars it is possible to register validation rules during process startup time before values of all vars are actually known.

var Vars VarSet

Vars is the default set of placeholder vars used by the process.

Individual packages may register vars here during init() time.

func (*VarSet) Register

func (vs *VarSet) Register(name string, value func(context.Context) (string, error))

Register registers a variable that can be used in templates as `${name}`.

Such placeholder variable is rendered into an actual value via the given callback in RenderTemplate.

The primary use case for this mechanism is to allow to register config validation rule patterns that depend on not-yet known values during init() time.

Panics if such variable is already registered.

func (*VarSet) RenderTemplate

func (vs *VarSet) RenderTemplate(ctx context.Context, templ string) (string, error)

RenderTemplate replaces all `${var}` references in the string with their values by calling registered callbacks.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to