Documentation ¶
Index ¶
- Variables
- func IsUnknownFileTypeError(err error) bool
- func UnknownFileTypeError(err error) error
- type CanMutate
- type MultiSource
- func (m *MultiSource) AddSource(source Source)
- func (m *MultiSource) Copy() *MultiSource
- func (m *MultiSource) Exists(keys ...string) bool
- func (m *MultiSource) GetBool(keys ...string) (bool, error)
- func (m *MultiSource) GetFloat(keys ...string) (float64, error)
- func (m *MultiSource) GetInt(keys ...string) (int64, error)
- func (m *MultiSource) GetString(keys ...string) (string, error)
- func (m *MultiSource) Keys(keys ...string) ([]string, error)
- func (m *MultiSource) Len(keys ...string) (int, error)
- func (m *MultiSource) Mutate(mutation Mutation) Source
- func (m *MultiSource) Recurse(keys ...string) Source
- func (m *MultiSource) Type(keys ...string) NodeType
- type Mutation
- type NodeType
- type Source
- func CombineSources(sources ...Source) Source
- func NewPrefixSource(source Source, prefix ...string) Source
- func UnmarshalFile(file string, args ...UnmarshalFileArg) (Source, error)
- func UnmarshalJSON(data []byte) (Source, error)
- func UnmarshalYAML(data []byte) (Source, error)
- func WithOffset(source Source, offsets ...int) Source
- type UnmarshalFileArg
Constants ¶
This section is empty.
Variables ¶
var ErrDoesNotExist = fmt.Errorf("requested item does not exist")
var ErrWrongType = fmt.Errorf("requested item is not the requested type")
Functions ¶
func IsUnknownFileTypeError ¶
func UnknownFileTypeError ¶
UnknownFileType annotates an error as being caused by not knowing the file type.
Types ¶
type CanMutate ¶
CanMutate must be implemented by sources that wrap or contain other sources. The Mutate method allows the wrapped sources to be rewrapped or modifed in some way. The mutation only applies to the inner source, not the source that CanMutate.
type MultiSource ¶
type MultiSource struct {
// contains filtered or unexported fields
}
func NewMultiSource ¶
func NewMultiSource(sources ...Source) *MultiSource
NewMultiSource creates a source that is the combination of multiple sources. For containers (maps, slices) this new source combines the elements from the provided sources. For scalar values, it takes its value from the first source that has a value present for the field in question.
func (*MultiSource) AddSource ¶
func (m *MultiSource) AddSource(source Source)
AddSource adds an additional source to a MultiSource, modifying the MultiSource
func (*MultiSource) Copy ¶
func (m *MultiSource) Copy() *MultiSource
func (*MultiSource) Exists ¶
func (m *MultiSource) Exists(keys ...string) bool
func (*MultiSource) Mutate ¶
func (m *MultiSource) Mutate(mutation Mutation) Source
func (*MultiSource) Recurse ¶
func (m *MultiSource) Recurse(keys ...string) Source
func (*MultiSource) Type ¶
func (m *MultiSource) Type(keys ...string) NodeType
type Mutation ¶
Mutation is a function that transforms a source into a new source
func MultiSourceSetCombine ¶
MultiSourceSetCombine sets the behvior for which how many sources are used for slices and maps in a MultiSource. The default is true: slices and maps are combined. Slices are appended and maps are combined.
If combine is false there can be some surprising behavior because paths may exist beyond what keys says. For example, suppose we have two objects:
one: map: key1: value1 two: map: key2: value2
With combine=false, keys(map) = [key1] but lookup(map.key2) = value2
func MultiSourceSetFirst ¶
MultiSourceSetFirst sets the priority for which source is evaluated first for MultiSource sources. For scalars (int, string, etc), the first evaluated source that has a value is the value returned. The default is first=true which means that the first (not last) source wins.
type Source ¶
type Source interface { Exists(keys ...string) bool GetBool(keys ...string) (bool, error) GetInt(keys ...string) (int64, error) GetFloat(keys ...string) (float64, error) GetString(keys ...string) (string, error) Recurse(keys ...string) Source // can return nil Keys(keys ...string) ([]string, error) Len(keys ...string) (int, error) Type(keys ...string) NodeType }
Source is an abstraction of model encodings. If you need to work with arbitray encodings of data models, you either need to unpack the encoded data into a interface{} or you need an abstraction. This is such an abstraction.
func CombineSources ¶
CombineSources expects any MultiSource to be the first source provided. Nil sources are allowed and filtered out. The result may be nil if all inputs are nil.
func NewPrefixSource ¶
NewPrefixSource wraps a Source such that it applies a path prefix to the entire source.
func UnmarshalFile ¶
func UnmarshalFile(file string, args ...UnmarshalFileArg) (Source, error)
func UnmarshalJSON ¶
func UnmarshalYAML ¶
func WithOffset ¶ added in v0.1.0
WithOffset returns a modified source that offsets slice lookups such that it requires a larger key to do the lookup.
type UnmarshalFileArg ¶
type UnmarshalFileArg func(*unmarshalOpts)
func WithFS ¶
func WithFS(fs fs.FS) UnmarshalFileArg