Back to godoc.org

Package vars

v0.0.0-...-1557bcf
Latest Go to latest

The latest major version is .

Published: Aug 13, 2020 | License: Apache-2.0 | Module: github.com/luci/luci-go

Overview

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

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

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