Documentation
¶
Overview ¶
Package parser implements decoding and encoding between a flat map of labels and a typed Configuration.
Index ¶
- Constants
- func AddMetadata(element interface{}, node *Node, opts MetadataOpts) error
- func Decode(labels map[string]string, element interface{}, rootName string, ...) error
- func Encode(element interface{}, rootName string) (map[string]string, error)
- func EncodeNode(node *Node) map[string]string
- func Fill(element interface{}, node *Node, opts FillerOpts) error
- func IsExported(f reflect.StructField) bool
- type EncoderToNodeOpts
- type FillerOpts
- type Flat
- type FlatOpts
- type MetadataOpts
- type Node
Constants ¶
const ( // TagLabel allows to apply a custom behavior. // - "allowEmpty": allows to create an empty struct. // - "-": ignore the field. TagLabel = "label" // TagLabelSliceAsStruct allows to use a slice of struct by creating one entry into the slice. // The value is the substitution name used in the label to access the slice. TagLabelSliceAsStruct = "label-slice-as-struct" // TagDescription is the documentation for the field. // - "-": ignore the field. TagDescription = "description" // TagLabelAllowEmpty is related to TagLabel. TagLabelAllowEmpty = "allowEmpty" )
const DefaultRootName = "traefik"
DefaultRootName is the default name of the root node and the prefix of element name from the resources.
const MapNamePlaceholder = "<name>"
MapNamePlaceholder is the placeholder for the map name.
Variables ¶
This section is empty.
Functions ¶
func AddMetadata ¶
func AddMetadata(element interface{}, node *Node, opts MetadataOpts) error
AddMetadata adds metadata such as type, inferred from element, to a node.
func Decode ¶
func Decode(labels map[string]string, element interface{}, rootName string, filters ...string) error
Decode decodes the given map of labels into the given element. If any filters are present, labels which do not match the filters are skipped. The operation goes through three stages roughly summarized as: labels -> tree of untyped nodes untyped nodes -> nodes augmented with metadata such as kind (inferred from element) "typed" nodes -> typed element
func EncodeNode ¶
EncodeNode Converts a node to labels. nodes -> labels
func Fill ¶
func Fill(element interface{}, node *Node, opts FillerOpts) error
Fill populates the fields of the element using the information in node.
func IsExported ¶
func IsExported(f reflect.StructField) bool
IsExported reports whether f is exported. https://golang.org/pkg/reflect/#StructField
Types ¶
type EncoderToNodeOpts ¶ added in v2.2.0
EncoderToNodeOpts Options for the encoderToNode.
type FillerOpts ¶ added in v2.2.0
type FillerOpts struct {
AllowSliceAsStruct bool
}
FillerOpts Options for the filler.
type Flat ¶
Flat is a configuration item representation.
func EncodeToFlat ¶
EncodeToFlat encodes a node to a Flat representation. Even though the given node argument should have already been augmented with metadata such as kind, the element (and its type information) is still needed to treat remaining edge cases.
type FlatOpts ¶
type FlatOpts struct { Case string // "lower" or "upper", defaults to "lower". Separator string SkipRoot bool TagName string }
FlatOpts holds options used when encoding to Flat.
type MetadataOpts ¶ added in v2.2.0
MetadataOpts Options for the metadata.
type Node ¶
type Node struct { Name string `json:"name"` Description string `json:"description,omitempty"` FieldName string `json:"fieldName"` Value string `json:"value,omitempty"` Disabled bool `json:"disabled,omitempty"` Kind reflect.Kind `json:"kind,omitempty"` Tag reflect.StructTag `json:"tag,omitempty"` Children []*Node `json:"children,omitempty"` }
Node is a label node.
func DecodeToNode ¶
DecodeToNode converts the labels to a tree of nodes. If any filters are present, labels which do not match the filters are skipped.
func EncodeToNode ¶
func EncodeToNode(element interface{}, rootName string, opts EncoderToNodeOpts) (*Node, error)
EncodeToNode converts an element to a node. element -> nodes