Documentation ¶
Overview ¶
Package globals provides functions for loading globals.
Index ¶
Constants ¶
const ( ErrEval errors.Kind = "global eval" ErrRedefined errors.Kind = "global redefined" )
Errors returned when parsing and evaluating globals.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EvalReport ¶
type EvalReport struct { // Globals are the evaluated globals. Globals *eval.Object // BootstrapErr is for the case of errors happening before the evaluation. BootstrapErr error // Errors is a map of errors for each global. Errors map[GlobalPathKey]EvalError // map of GlobalPath to its EvalError. }
EvalReport is the report for the evaluation globals.
func ForDir ¶
ForDir loads all the globals from the cfgdir. It will navigate the configuration tree up from the dir until it reaches root, loading globals and merging them appropriately.
More specific globals (closer or at the current dir) have precedence over less specific globals (closer or at the root dir).
func ForStack ¶
func ForStack(root *config.Root, stack *config.Stack) EvalReport
ForStack loads from the config tree all globals defined for a given stack.
func NewEvalReport ¶
func NewEvalReport() EvalReport
NewEvalReport creates a new globals evaluation report.
func (*EvalReport) AsError ¶
func (r *EvalReport) AsError() error
AsError returns an error != nil if there's any error in the report.
type Expr ¶
type Expr struct { // Origin is the filename where this expression can be found. Origin info.Range // ConfigDir is the directory which loaded this expression. ConfigDir project.Path // LabelPath denotes the target accessor path which the expression must // be assigned into. LabelPath eval.ObjectPath hhcl.Expression }
Expr is an unevaluated global expression.
type ExprSet ¶
type ExprSet struct {
// contains filtered or unexported fields
}
ExprSet represents a set of globals loaded from a dir. The origin is the path of the dir from where all expressions were loaded.
type GlobalPathKey ¶
type GlobalPathKey struct {
// contains filtered or unexported fields
}
GlobalPathKey represents a global object accessor to be used as map key. The reason is that slices cannot be used as map key because the equality operator is not defined, then this type implements a fixed size struct.
func NewGlobalAttrPath ¶
func NewGlobalAttrPath(basepath []string, name string) GlobalPathKey
NewGlobalAttrPath creates a new global path key for an attribute.
func NewGlobalExtendPath ¶
func NewGlobalExtendPath(path []string) GlobalPathKey
NewGlobalExtendPath creates a new global path key for extension purposes only.
func (GlobalPathKey) Path ¶
func (a GlobalPathKey) Path() []string
Path returns the global accessor path (labels + attribute name).
type HierarchicalExprs ¶
HierarchicalExprs contains all loaded global expressions from multiple configuration directories (the key). Each configuration dir path is mapped to its global expressions.
func LoadExprs ¶
func LoadExprs(tree *config.Tree) (HierarchicalExprs, error)
LoadExprs loads from the file system all globals expressions defined for the given directory. It will navigate the file system from dir until it reaches rootdir, loading globals expressions and merging them appropriately. More specific globals (closer or at the dir) have precedence over less specific globals (closer or at the root dir).
func (HierarchicalExprs) Eval ¶
func (dirExprs HierarchicalExprs) Eval(ctx *eval.Context) EvalReport
Eval evaluates all global expressions and returns an EvalReport.
func (HierarchicalExprs) SetOverride ¶
func (dirExprs HierarchicalExprs) SetOverride( dir project.Path, path GlobalPathKey, expr hhcl.Expression, origin info.Range, )
SetOverride sets a custom global at the specified directory, using the given global path and expr. The origin is only used for debugging purposes.