Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(node *yaml.Node) (bool, error)
- func DecodeFirstRootNode(reader io.Reader) (*yaml.Node, error)
- func DecodeRootNodes(reader io.Reader) ([]*yaml.Node, error)
- func Document(node *yaml.Node) (*yaml.Node, error)
- func Float64(node *yaml.Node) (float64, error)
- func Int(node *yaml.Node) (int, error)
- func Map(node *yaml.Node) (map[string]*yaml.Node, errutil.Slice)
- func NewNodeWithValue(node *yaml.Node, val any) (*yaml.Node, error)
- func PrettyNodeTypeName(node *yaml.Node) string
- func Sequence(node *yaml.Node) ([]*yaml.Node, error)
- func String(node *yaml.Node) (string, error)
- func Uint(node *yaml.Node) (uint, error)
- func VarSubNodeRec(node *yaml.Node, source varsub.Source) (*yaml.Node, error)
- func VarSubStringNode(str StringNode, source varsub.Source) (*yaml.Node, error)
- func VerifyKind(node *yaml.Node, wantStr string, wantKind yaml.Kind) error
- func VerifyKindAndTag(node *yaml.Node, wantStr string, wantKind yaml.Kind, wantTag string) error
- func VerifyTag(node *yaml.Node, wantStr string, wantTag string) error
- type MapItem
- type MapVisitor
- func (p MapVisitor) AddErrorFor(key string, errSlice *errutil.Slice, err error)
- func (p MapVisitor) HasNode(key string) bool
- func (p MapVisitor) LookupBoolFromVarSub(varLookup string, target *bool) error
- func (p MapVisitor) LookupIntFromVarSub(varLookup string, target *int) error
- func (p MapVisitor) LookupNumberFromVarSub(varLookup string, target *float64) error
- func (p MapVisitor) LookupStringFromVarSub(varLookup string, target *string) error
- func (p MapVisitor) LookupUintFromVarSub(varLookup string, target *uint) error
- func (p MapVisitor) ParentPos() Pos
- func (p MapVisitor) ReadNodesPos() map[string]Pos
- func (p MapVisitor) RequireBoolFromVarSub(varLookup string, target *bool) error
- func (p MapVisitor) RequireIntFromVarSub(varLookup string, target *int) error
- func (p MapVisitor) RequireNumberFromVarSub(varLookup string, target *float64) error
- func (p MapVisitor) RequireStringFromVarSub(varLookup string, target *string) error
- func (p MapVisitor) RequireUintFromVarSub(varLookup string, target *uint) error
- func (p MapVisitor) ValidateRequiredSlice(key string) error
- func (p MapVisitor) ValidateRequiredString(key string) error
- func (p MapVisitor) VisitBool(key string, target *bool) error
- func (p MapVisitor) VisitInt(key string, target *int) error
- func (p MapVisitor) VisitNumber(key string, target *float64) error
- func (p MapVisitor) VisitString(key string, target *string) error
- func (p MapVisitor) VisitStringSlice(key string, target *[]string) errutil.Slice
- func (p MapVisitor) VisitStringStringMap(key string, target *map[string]string) errutil.Slice
- func (p MapVisitor) VisitStringWithVarSub(nodeKey, varLookup string, target *string) error
- func (p MapVisitor) VisitUint(key string, target *uint) error
- type Pos
- type StringNode
- type VarSubNode
Constants ¶
const ( ShortTagString = "!!str" ShortTagNull = "!!null" ShortTagInt = "!!int" ShortTagFloat = "!!float" ShortTagBool = "!!bool" ShortTagMap = "!!map" ShortTagSeq = "!!seq" ShortTagTimestamp = "!!timestamp" ShortTagMerge = "!!merge" )
YAML short tag names.
Variables ¶
var ( ErrMissingRequired = errors.New("missing required field") ErrMissingBuiltinVar = errors.New("missing built-in var") )
Errors for the MapVisitor
var ( ErrInvalidFieldType = errors.New("invalid field type") ErrKeyCollision = errors.New("map key appears more than once") ErrKeyEmpty = errors.New("map key must not be empty") ErrKeyNotString = errors.New("map key must be string") ErrMissingDoc = errors.New("empty document") ErrTooManyDocs = errors.New("only 1 document is allowed") )
Generic errors related to visiting YAML nodes.
var (
ErrUnsupportedVarSubType = errors.New("unsupported variable substitution value")
)
Errors specific to performing variable substitution on nodes.
Functions ¶
func DecodeFirstRootNode ¶
DecodeFirstRootNode returns the first YAML root node from the first parsed document. If there are multiple documents then the first document is returned together with an error.
func DecodeRootNodes ¶
DecodeRootNodes returns the list of YAML root nodes from all documents in the parsed input.
func Document ¶
func Document(node *yaml.Node) (*yaml.Node, error)
Document will try to read the root node of this document YAML node.
func NewNodeWithValue ¶
NewNodeWithValue creates a new YAML node with the correct kind and tag depending on the reflected type.
func PrettyNodeTypeName ¶
func PrettyNodeTypeName(node *yaml.Node) string
PrettyNodeTypeName will return a human-readable type name of a node.
func Sequence ¶
func Sequence(node *yaml.Node) ([]*yaml.Node, error)
Sequence will try to read this YAML node as a sequence of nodes (array).
func VarSubNodeRec ¶
VarSubNodeRec will perform variable substitution recursively on a YAML node tree.
func VarSubStringNode ¶
func VarSubStringNode(str StringNode, source varsub.Source) (*yaml.Node, error)
VarSubStringNode will perform variable substitution on a string node and return a new node with the substituted value.
func VerifyKind ¶
VerifyKind checks if the given node has the wanted kind. The wantStr is only used as a pretty string of the wanted type in the potential error message.
func VerifyKindAndTag ¶
VerifyKindAndTag checks if the given node has the wanted kind and tag. The wantStr is only used as a pretty string of the wanted type in the potential error message.
Types ¶
type MapItem ¶
type MapItem struct { Key StringNode Value *yaml.Node }
MapItem is a key-value pair item from a YAML map node.
type MapVisitor ¶
type MapVisitor struct {
// contains filtered or unexported fields
}
MapVisitor is a utility type that can visit nodes from a map of nodes by key, allowing simpler parsing of a map node with many different field types.
func NewMapVisitor ¶
func NewMapVisitor(parent *yaml.Node, nodes map[string]*yaml.Node, source varsub.Source) MapVisitor
NewMapVisitor creates a new type that can visit nodes from a map of nodes by key, allowing simpler parsing of a map node with many different field types.
func (MapVisitor) AddErrorFor ¶
func (p MapVisitor) AddErrorFor(key string, errSlice *errutil.Slice, err error)
AddErrorFor will add an error to the slice of errors with errutil.Pos and errutil.Scoped errors wrapped around it, using the node's position and key name respectively.
func (MapVisitor) HasNode ¶
func (p MapVisitor) HasNode(key string) bool
HasNode returns a boolean if the node is defined. A YAML node with the value null will still return true.
func (MapVisitor) LookupBoolFromVarSub ¶
func (p MapVisitor) LookupBoolFromVarSub(varLookup string, target *bool) error
LookupBoolFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned on type error. If the variable is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) LookupIntFromVarSub ¶
func (p MapVisitor) LookupIntFromVarSub(varLookup string, target *int) error
LookupIntFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned on type error. If the variable is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) LookupNumberFromVarSub ¶
func (p MapVisitor) LookupNumberFromVarSub(varLookup string, target *float64) error
LookupNumberFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned on type error. If the variable is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) LookupStringFromVarSub ¶
func (p MapVisitor) LookupStringFromVarSub(varLookup string, target *string) error
LookupStringFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned on type error. If the variable is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) LookupUintFromVarSub ¶
func (p MapVisitor) LookupUintFromVarSub(varLookup string, target *uint) error
LookupUintFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned on type error. If the variable is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) ParentPos ¶
func (p MapVisitor) ParentPos() Pos
ParentPos returns the position of the map node's parent.
func (MapVisitor) ReadNodesPos ¶
func (p MapVisitor) ReadNodesPos() map[string]Pos
ReadNodesPos returns a map of the positions of all the nodes that have been visited so far.
func (MapVisitor) RequireBoolFromVarSub ¶
func (p MapVisitor) RequireBoolFromVarSub(varLookup string, target *bool) error
RequireBoolFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned if the looked up variable is not found or on type errors.
func (MapVisitor) RequireIntFromVarSub ¶
func (p MapVisitor) RequireIntFromVarSub(varLookup string, target *int) error
RequireIntFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned if the looked up variable is not found or on type errors.
func (MapVisitor) RequireNumberFromVarSub ¶
func (p MapVisitor) RequireNumberFromVarSub(varLookup string, target *float64) error
RequireNumberFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned if the looked up variable is not found or on type errors.
func (MapVisitor) RequireStringFromVarSub ¶
func (p MapVisitor) RequireStringFromVarSub(varLookup string, target *string) error
RequireStringFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned if the looked up variable is not found or on type errors.
func (MapVisitor) RequireUintFromVarSub ¶
func (p MapVisitor) RequireUintFromVarSub(varLookup string, target *uint) error
RequireUintFromVarSub looks up a value from the predefined varsub.Source and writes the value to the pointer. An error is returned if the looked up variable is not found or on type errors.
func (MapVisitor) ValidateRequiredSlice ¶
func (p MapVisitor) ValidateRequiredSlice(key string) error
ValidateRequiredSlice will return an error if the node at the given key is not found or is an empty slice.
func (MapVisitor) ValidateRequiredString ¶
func (p MapVisitor) ValidateRequiredString(key string) error
ValidateRequiredString will return an error if the node at the given key is not found or is an empty string.
func (MapVisitor) VisitBool ¶
func (p MapVisitor) VisitBool(key string, target *bool) error
VisitBool reads a node by string key and writes the parsed bool value to the pointer. An error is returned on parse error. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitInt ¶
func (p MapVisitor) VisitInt(key string, target *int) error
VisitInt reads a node by string key and writes the parsed int value to the pointer. An error is returned on parse error. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitNumber ¶
func (p MapVisitor) VisitNumber(key string, target *float64) error
VisitNumber reads a node by string key and writes the parsed float64 value to the pointer. An error is returned on parse error. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitString ¶
func (p MapVisitor) VisitString(key string, target *string) error
VisitString reads a node by string key and writes the string value to the pointer. An error is returned on type error. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitStringSlice ¶
func (p MapVisitor) VisitStringSlice(key string, target *[]string) errutil.Slice
VisitStringSlice reads a node by string key and writes the string values to the pointer. A slice of error contains any type errors. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitStringStringMap ¶
VisitStringStringMap reads a node by string key and writes the string key-value pairs to the pointer. A slice of error contains any type errors. If the node is not present, then nil is returned and the pointer is untouched.
func (MapVisitor) VisitStringWithVarSub ¶
func (p MapVisitor) VisitStringWithVarSub(nodeKey, varLookup string, target *string) error
VisitStringWithVarSub will try to find a variable from the predefined varsub.Source and use that as a default if the node at the given key is not present. An error is returned on type errors.
type Pos ¶
Pos represents a position. Used to declare where an object was defined in the .wharf-ci.yml file. The first line and column starts at 1. The zero value is used to represent an undefined position.
func NewPosFromNode ¶
func NewPosFromNode(node *yaml.Node) Pos
NewPosFromNode creates a new Pos using a YAML node's Line and Column.
type StringNode ¶
type StringNode struct { Node *yaml.Node Value string }
StringNode is a node with known string type, with both the string value and original node available.
type VarSubNode ¶
type VarSubNode struct {
Node *yaml.Node
}
VarSubNode is a custom varsub variable type that envelops a YAML node. Mostly only used internally inside the wharfyml package.
func (VarSubNode) String ¶
func (v VarSubNode) String() string
String implements the fmt.Stringer interface.