container

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

func SliceToDotPath(path []string) string

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

func Make(v interface{}) (Container, error)

Make creates new container from interface, if given argument is already container it will clone its content and return container directly

func New

func New() Container

New returns new container, basically empty map wrapped in gabs.

func ReadFile

func ReadFile(file string) (c Container, err error)

ReadFile reads extension and unmarshal .yaml, .yml, .json to container. Also stores path of given file, later available with FilePath().

func ReadJSON

func ReadJSON(data []byte) (c Container, err error)

ReadJSON will read data and return new container.

func ReadYAML

func ReadYAML(data []byte) (c Container, err error)

ReadYAML will read yaml and returns its content wrapped in container.

func Zero

func Zero() Container

Zero returns empty container.

func (Container) Bytes

func (c Container) Bytes() []byte

Bytes marshals an element to a JSON []byte blob.

func (Container) ChildrenMap

func (c Container) ChildrenMap() (map[string]Container, error)

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

func (c Container) Clone() Container

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) ExistsP

func (c Container) ExistsP(path string) bool

ExistsP checks whether a dot notation path exists.

func (Container) FilePath

func (c Container) FilePath() string

FilePath returns file path of given container if was ReadFile was used.

func (Container) Flatten

func (c Container) Flatten() (map[string]interface{}, error)

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) IsNil

func (c Container) IsNil() bool

IsNil reports if underlying value of container is nil.

func (Container) MarshalIndentJSON

func (c Container) MarshalIndentJSON(prefix string, indent string) ([]byte, error)

MarshalIndentJSON same oas what would you expect from stdlib.

func (Container) MarshalJSON

func (c Container) MarshalJSON() ([]byte, error)

MarshalJSON will marshal given data into json.

func (Container) MarshalYAML

func (c Container) MarshalYAML() ([]byte, error)

MarshalYAML uses gopkg.in/yaml.v2 to povide yaml serialization.

func (Container) Merge

func (c Container) Merge(source Container, collisionFn Merger) error

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

func (c Container) Path(x string) Container

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) Print

func (c Container) Print(log logging.Printer)

Print will print yaml definition of given container to Printer.

func (Container) SetP

func (c Container) SetP(path string, value interface{}) (err error)

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

type MapItem struct {
	Key   string
	Val   interface{}
	Index int
}

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

func ExtractKey(c Container, key string) (pp MapSlice, err error)

ExtractKey will extract keys from container

func (MapSlice) Len

func (ms MapSlice) Len() int

func (MapSlice) Less

func (ms MapSlice) Less(i, j int) bool

func (MapSlice) MarshalJSON

func (ms MapSlice) MarshalJSON() ([]byte, error)

MarshalJSON for map slice.

func (MapSlice) MarshalYAML

func (ms MapSlice) MarshalYAML() (interface{}, error)

MarshalYAML will marshal yaml to MapSlice.

func (MapSlice) Sort

func (ms MapSlice) Sort() MapSlice

Sort will sort items by index and return copy

func (MapSlice) Swap

func (ms MapSlice) Swap(i, j int)

func (MapSlice) Values

func (ms MapSlice) Values() (vx []interface{})

Values returns values of 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

func NewSortMarshaller(c Container, s SorterFn) Sorter

NewSortMarshaller makes new marshaller with sorting provided in second argument.

func (Sorter) MarshalIndentJSON

func (c Sorter) MarshalIndentJSON(prefix string, indent string) ([]byte, error)

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

func (c Sorter) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of container.

func (Sorter) MarshalYAML

func (c Sorter) MarshalYAML() ([]byte, error)

MarshalYAML serializes the value provided into a YAML document. The structure of the generated document will reflect the structure of the value itself.

type SorterFn

type SorterFn func(string, interface{}) (interface{}, error)

SorterFn is sorting function

func SortMapMarhsaler

func SortMapMarhsaler(order []string) SorterFn

SortMapMarhsaler is one of sorting functions allowing to sorty by "order" which is supplied as a first argument.

Jump to

Keyboard shortcuts

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