Documentation ¶
Index ¶
- func MergeDefault(dest, source interface{}) (interface{}, error)
- func MergeOverride(dest, source interface{}) (interface{}, error)
- func MergeStrict(dest, source interface{}) (interface{}, error)
- func SliceToDotPath(path []string) string
- type Container
- func (c Container) Bytes() []byte
- func (c Container) ChildrenMap() (map[string]Container, error)
- func (c Container) Clone() Container
- func (c Container) Data() interface{}
- func (c Container) ExistsP(path string) bool
- func (c Container) FilePath() string
- func (c Container) Flatten() (map[string]interface{}, error)
- func (c Container) IsNil() bool
- func (c Container) MarshalIndentJSON(prefix string, indent string) ([]byte, error)
- func (c Container) MarshalJSON() ([]byte, error)
- func (c Container) MarshalYAML() ([]byte, error)
- func (c Container) Merge(source Container, collisionFn Merger) error
- func (c Container) Path(x string) Container
- func (c Container) Print(log logging.Printer)
- func (c Container) SetP(path string, value interface{}) (err error)
- type Containers
- type MapItem
- type MapSlice
- type Merger
- type Sorter
- type SorterFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeDefault ¶
func MergeDefault(dest, source interface{}) (interface{}, error)
MergeDefault will merge default
func MergeOverride ¶
func MergeOverride(dest, source interface{}) (interface{}, error)
MergeOverride will merge with override
func MergeStrict ¶
func MergeStrict(dest, source interface{}) (interface{}, error)
MergeStrict will merge strictly, no collisions
func SliceToDotPath ¶
SliceToDotPath converts slice into dot path
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is a wrapper around gabs.Container. Overall you probably dont need this wrapper. Use gabs directly.
func Make ¶
Make creates new container from interface, if given argument is already container it will clone its content and return container directly
func ReadFile ¶
ReadFile reads extension and unmarshal .yaml, .yml, .json to container. Also stores path of given file, later available with FilePath().
func (Container) ChildrenMap ¶
ChildrenMap returns a map of all the children of an object element. IF the underlying value isn't a object then an empty map is returned.
func (Container) Clone ¶
Clone will clone container. Returning its copy. This is done using Marshal & Unmarhsal of given container.
func (Container) Data ¶
func (c Container) Data() interface{}
Data returns the underlying value of the target element in the wrapped structure.
func (Container) Flatten ¶
Flatten a JSON array or object into an object of key/value pairs for each field, where the key is the full path of the structured field in dot path notation matching the spec for the method Path.
E.g. the structure `{"foo":[{"bar":"1"},{"bar":"2"}]}` would flatten into the object: `{"foo.0.bar":"1","foo.1.bar":"2"}`. `{"foo": [{"bar":[]},{"bar":{}}]}` would flatten into the object `{}`
Returns an error if the target is not a JSON object or array.
func (Container) MarshalIndentJSON ¶
MarshalIndentJSON same oas what would you expect from stdlib.
func (Container) MarshalJSON ¶
MarshalJSON will marshal given data into json.
func (Container) MarshalYAML ¶
MarshalYAML uses gopkg.in/yaml.v2 to povide yaml serialization.
func (Container) Merge ¶
Merge merges two objects using a provided function to resolve collisions.
The collision function receives two interface{} arguments, destination (the original object) and source (the object being merged into the destination). Which ever value is returned becomes the new value in the destination object at the location of the collision.
func (Container) Path ¶
Path searches the wrapped structure following a path in dot notation, segments of this path are searched according to the same rules as Search.
Because the characters '~' (%x7E) and '.' (%x2E) have special meanings in this pkg paths, '~' needs to be encoded as '~0' and '.' needs to be encoded as '~1' when these characters appear in a reference key.
func (Container) SetP ¶
SetP sets the value of a field at a path using dot notation, any parts of the path that do not exist will be constructed, and if a collision occurs with a non object type whilst iterating the path an error is returned. Unline original method of gabs it will clone the source value, making sure one container dosnt affect other one.
type Containers ¶
type Containers []Container
Containers list of containers, allowing to do some additional magic.
func ReadDir ¶
func ReadDir(dir string, patterns ...string) (cc Containers, err error)
ReadDir will read director and parse yaml/json files. It is using glob to search for file in given directory. by defaut it will search for yaml,yml,json extension. But you are free to supply your own if you have different extension.
func (Containers) Len ¶
func (cc Containers) Len() int
func (Containers) Less ¶
func (cc Containers) Less(i, j int) bool
func (Containers) Merge ¶
func (cc Containers) Merge(fn Merger) (Container, error)
Merge will allow you to merge multiple containers together.
func (Containers) Sort ¶
func (cc Containers) Sort() Containers
Sort will clone containers and return is sorted copy
func (Containers) Swap ¶
func (cc Containers) Swap(i, j int)
type MapItem ¶
MapItem representation of one map item. MapItem is used internally by yaml pkg to provide key/value structure allowing object to be serialozed as array. By setting Index you are setting position of key in object.
type MapSlice ¶
type MapSlice []MapItem
MapSlice of map items.
func ExtractKey ¶
ExtractKey will extract keys from container
func (MapSlice) MarshalJSON ¶
MarshalJSON for map slice.
func (MapSlice) MarshalYAML ¶
MarshalYAML will marshal yaml to MapSlice.
type Merger ¶
type Merger func(destination, source interface{}) (interface{}, error)
Merger is function signature allowing merging
type Sorter ¶
type Sorter struct { Container // contains filtered or unexported fields }
Sorter wraps container and allows and provides new Masrshaling interface.
func NewSortMarshaller ¶
NewSortMarshaller makes new marshaller with sorting provided in second argument.
func (Sorter) MarshalIndentJSON ¶
MarshalIndentJSON is like Marshal but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.
func (Sorter) MarshalJSON ¶
MarshalJSON returns the JSON encoding of container.
func (Sorter) MarshalYAML ¶
MarshalYAML serializes the value provided into a YAML document. The structure of the generated document will reflect the structure of the value itself.