Documentation ¶
Index ¶
- func Get(i interface{}, path string) (interface{}, error)
- func NewInvalidKeyError(v interface{}) error
- func NewInvalidPathError(message string) error
- func Update(i interface{}, path string, value interface{}) (interface{}, error)
- type Accessor
- type DummyAccessor
- type InvalidKeyError
- type InvalidPathError
- type MapAccessor
- type NoSuchPathError
- type Path
- type SliceAccessor
- type ValueAccessor
- func (a *ValueAccessor) Foreach(f func(path Path, value interface{}) error) error
- func (a *ValueAccessor) Get(path Path) (Accessor, error)
- func (a *ValueAccessor) MarshalJSON() ([]byte, error)
- func (a *ValueAccessor) MarshalText() ([]byte, error)
- func (a ValueAccessor) MarshalYAML() (interface{}, error)
- func (a *ValueAccessor) Set(path Path, value interface{}) error
- func (a *ValueAccessor) Unwrap() interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewInvalidKeyError ¶
func NewInvalidKeyError(v interface{}) error
NewInvalidKeyError createa InvalidKeyError.
func NewInvalidPathError ¶
NewInvalidPathError creates a InvalidKeyError.
Types ¶
type Accessor ¶
type Accessor interface { // Get finds a object at specific path. // NoSuchPathError is returned when no object was found in the path. Get(path Path) (Accessor, error) // Set set a object into specific path. // NoSuchPathError is returned when the path is invalid. Set(path Path, value interface{}) error // Unwrap unwraps the object and returns actual value. Unwrap() interface{} // Foreach enumerates all value in the object. Foreach(f func(path Path, value interface{}) error) error }
Accessor provides getter/setter to the object.
func NewAccessor ¶
NewAccessor creates a new Accessor from a object. The object is a map[string]interface{} or []interface{}.
type DummyAccessor ¶
type DummyAccessor struct {
ID int
}
DummyAccessor is the Accessor for testing.
func (DummyAccessor) Foreach ¶
func (a DummyAccessor) Foreach(f func(path Path, value interface{}) error) error
Foreach implements Accessor.
func (DummyAccessor) Get ¶
func (a DummyAccessor) Get(path Path) (Accessor, error)
Get implements Accessor.
func (DummyAccessor) Set ¶
func (a DummyAccessor) Set(path Path, _ interface{}) error
Set implements Accessor.
func (DummyAccessor) Unwrap ¶
func (a DummyAccessor) Unwrap() interface{}
Unwrap implements Accessor.
type InvalidKeyError ¶
type InvalidKeyError struct {
Value interface{}
}
InvalidKeyError is returned when a key type of the map was not a string.
func (*InvalidKeyError) Error ¶
func (e *InvalidKeyError) Error() string
type InvalidPathError ¶
type InvalidPathError struct {
Message string
}
InvalidPathError is returned when failing to create a Path.
func (*InvalidPathError) Error ¶
func (e *InvalidPathError) Error() string
type MapAccessor ¶
MapAccessor is the Accessor for a map.
func (MapAccessor) Foreach ¶
func (a MapAccessor) Foreach(f func(path Path, value interface{}) error) error
Foreach implements Accessor.
func (MapAccessor) Get ¶
func (a MapAccessor) Get(path Path) (Accessor, error)
Get implements Accessor.
func (MapAccessor) Set ¶
func (a MapAccessor) Set(path Path, value interface{}) error
Set implements Accessor.
type NoSuchPathError ¶
NoSuchPathError is returned when no key was found in the object.
func NewNoSuchPathError ¶
func NewNoSuchPathError(message string, key string, keys ...string) *NoSuchPathError
NewNoSuchPathError creates a NoSuchPathError.
func (*NoSuchPathError) Error ¶
func (e *NoSuchPathError) Error() string
func (*NoSuchPathError) PushKey ¶
func (e *NoSuchPathError) PushKey(key string)
PushKey push key to the head of the stack trace.
type Path ¶
type Path interface { fmt.Stringer // Key returns a head key of the sequence. Key() string // SubPath returns a path excluding the beginning. SubPath() (Path, bool) // PushKey add a key to the head of the sequence. PushKey(key string) Path }
Path is a sequence of object keys.
type SliceAccessor ¶
type SliceAccessor []Accessor
SliceAccessor is the Accessor for a slice.
func (SliceAccessor) Foreach ¶
func (a SliceAccessor) Foreach(f func(path Path, value interface{}) error) error
Foreach implements Accessor.
func (SliceAccessor) Get ¶
func (a SliceAccessor) Get(path Path) (Accessor, error)
Get implements Accessor.
func (SliceAccessor) Set ¶
func (a SliceAccessor) Set(path Path, value interface{}) error
Set implements Accessor.
func (SliceAccessor) Unwrap ¶
func (a SliceAccessor) Unwrap() interface{}
Unwrap implements Accessor.
type ValueAccessor ¶
type ValueAccessor struct {
Value interface{}
}
ValueAccessor is the Accessor for non-object types.
func (*ValueAccessor) Foreach ¶
func (a *ValueAccessor) Foreach(f func(path Path, value interface{}) error) error
Foreach implements Accessor.
func (*ValueAccessor) Get ¶
func (a *ValueAccessor) Get(path Path) (Accessor, error)
Get implements Accessor.
func (*ValueAccessor) MarshalJSON ¶
func (a *ValueAccessor) MarshalJSON() ([]byte, error)
MarshalJSON implements encoding/json.Marshaler.
func (*ValueAccessor) MarshalText ¶
func (a *ValueAccessor) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (ValueAccessor) MarshalYAML ¶
func (a ValueAccessor) MarshalYAML() (interface{}, error)
MarshalYAML implements github.com/go-yaml/yaml.Marshaler.
func (*ValueAccessor) Set ¶
func (a *ValueAccessor) Set(path Path, value interface{}) error
Set implements Accessor.
func (*ValueAccessor) Unwrap ¶
func (a *ValueAccessor) Unwrap() interface{}
Unwrap implements Accessor.