Documentation
¶
Index ¶
- func DocOutput(s interface{}) interface{}
- func Merge(x1, x2 interface{}) (interface{}, error)
- type Warning
- type Yaml
- func (y Yaml) Copy() Yaml
- func (y *Yaml) Decode(v interface{}) error
- func (y *Yaml) Encode(w io.Writer, indent int) error
- func (y *Yaml) FilterBy(filter string) error
- func (y *Yaml) FilterByKeys(keys []string) error
- func (y *Yaml) Insert(parentKeys []string, subelement interface{}) ([]Warning, error)
- func (y *Yaml) Merge(from Yaml) ([]Warning, error)
- func (y *Yaml) MergeBytes(from []byte) ([]Warning, error)
- func (y *Yaml) MergeSelective(from Yaml, selectFlag string) ([]Warning, error)
- func (y Yaml) SelectSubElement(keys []string) (Yaml, error)
- func (y *Yaml) Sort()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DocOutput ¶
func DocOutput(s interface{}) interface{}
DocOutput constructs a documentation interface from the provided struct by using the struct field types as well as the information given in the "doc" struct tag. In the doc tag the following information can be given in a comma-separated list:
- msg: describing message
- default: default value
- req: required field
- option,o: 1 possible value (multiple values are specified by multiple occurrences)
e.g.: `doc:"msg=this is my message,default=0,o=0, o=1, req"`. If no "doc" tag is present the field will be ignored. The output format is map[string]interface{}, where the interface is either a doc-string or a substructure of the same format.
func Merge ¶
func Merge(x1, x2 interface{}) (interface{}, error)
Merge merges x2 into x1. Merge rules are:
- maps are merged on matching keys
- any submap in from is added under the last matching key in into
- 2 slices are merged by appending the from slice to the into slice
- scalars from overwrite scalars in into
- for all other combinations Merge with return an error
Types ¶
type Warning ¶
Warning holds the ordered list of nested keys for which a warning occurred and the associated warning itself
type Yaml ¶
Yaml objects hold a yaml file in form of a yaml.Node object. This is the central object for all implementations in this package. The yaml.Node representation is recursive and every level of a yaml file is encoded into a dedicated yaml.Node. The different levels are nested via the yaml.Node.Content field. All Implementations in the yamlfile package follow this recursive approach and solve their requirements for each level in the recursive yaml.Node structure.
func NewFromInterface ¶
func PartialCopy ¶
PartialCopy creates a copy of the input n but with only the subslice of the content n.Content[start:end]
func (*Yaml) Encode ¶
Encode marshalls a Yaml into the provided Writer w. The number of space indentations in the output can be controlled via the indent parameter.
func (*Yaml) FilterBy ¶
FilterBy puts a positive filter on the Node in Yaml. Only elements remain that have the provided filter as a LineComment or a yaml Tag. E.g. for the filter "keepThis", the following yaml
key: "will be removed" persistentComment: "will stay" # keepThis persistentTag: !keepThis "will stay" root: nestedComment: "will stay" # keepThis nestedTag: !keepThis "will stay" # keepThis key: "will be removed"
turns into
persistentComment: "will stay" # keepThis persistentTag: !keepThis "will stay" root: nestedComment: "will stay" # keepThis nestedTag: !keepThis "will stay" # keepThis
func (*Yaml) FilterByKeys ¶
FilterByKeys traverses the Yaml object via the ordered slice of keys and removes all parts that are not children of the full keys slice.
For the key slice: ["willStay", "subkey"]
the Yaml object:
key1: "will be removed" key2: "will be removed" willStay: subkey: s1: "will stay" s2: "will stay" s3: ["will stay", "will stay"]
will be reduced to
willStay: subkey: s1: "will stay" s2: "will stay" s3: ["will stay", "will stay"]
func (*Yaml) Merge ¶
Merge merges the input Yaml (from) into the Yaml object (y). Merge rules are:
- maps are merged on matching keys
- any submap in from is added under the last matching key in into
- slices are merged following the 2 rules: 1) merges happen element by element 2) if the keys in sub-elements match, elements are deep-merged
- scalars from overwrite scalars in into
- all other combinations the object in into is overwritten with the object in from
The resulting Yaml object is NOT sorted.
func (*Yaml) MergeBytes ¶
Like Merge just with a raw input
func (*Yaml) MergeSelective ¶
MergeSelective merges the input Yaml (from) into the Yaml object (y). It follows the same merge rules as the Merge function. Before merging, the MergeSelective function filters the from Yaml by the selectFlag and will only keep the elements that have the relevant flag (as line comment or yaml flag).
The resulting Yaml object is NOT sorted.