parser

package
v2.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package parser implements decoding and encoding between a flat map of labels and a typed Configuration.

Index

Constants

View Source
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"
)
View Source
const DefaultRootName = "traefik"

DefaultRootName is the default name of the root node and the prefix of element name from the resources.

View Source
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 Encode

func Encode(element interface{}, rootName string) (map[string]string, error)

Encode converts an element to labels. element -> node (value) -> label (node).

func EncodeNode

func EncodeNode(node *Node) map[string]string

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

type EncoderToNodeOpts struct {
	OmitEmpty          bool
	TagName            string
	AllowSliceAsStruct bool
}

EncoderToNodeOpts Options for the encoderToNode.

type FillerOpts added in v2.2.0

type FillerOpts struct {
	AllowSliceAsStruct bool
}

FillerOpts Options for the filler.

type Flat

type Flat struct {
	Name        string
	Description string
	Default     string
}

Flat is a configuration item representation.

func EncodeToFlat

func EncodeToFlat(element interface{}, node *Node, opts FlatOpts) ([]Flat, error)

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

type MetadataOpts struct {
	TagName            string
	AllowSliceAsStruct bool
}

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

func DecodeToNode(labels map[string]string, rootName string, filters ...string) (*Node, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL