luci: go.chromium.org/luci/config/vars Index | Files

package vars

import "go.chromium.org/luci/config/vars"

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.

Index

Package Files

vars.go

type VarSet Uses

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 Uses

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 Uses

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.

Package vars imports 5 packages (graph) and is imported by 9 packages. Updated 2020-12-01. Refresh now. Tools for package owners.