Documentation
¶
Index ¶
- Variables
- func JsonEscape(i string) string
- func Merge(left map[string]interface{}, right map[string]interface{}) map[string]interface{}
- func UnmarshalConfig(config interface{}, object interface{}) error
- type JSONPath
- type JSONPaths
- type MultipleJSONPath
- func (mjp *MultipleJSONPath) FieldName() string
- func (mjp *MultipleJSONPath) Get(obj map[string]interface{}) (interface{}, bool)
- func (mjp *MultipleJSONPath) GetAndRemove(obj map[string]interface{}) (interface{}, bool)
- func (mjp *MultipleJSONPath) IsEmpty() bool
- func (mjp *MultipleJSONPath) Set(obj map[string]interface{}, value interface{}) error
- func (mjp *MultipleJSONPath) SetIfNotExist(obj map[string]interface{}, value interface{}) error
- func (mjp *MultipleJSONPath) SetOrMergeIfExist(obj map[string]interface{}, values map[string]interface{}) error
- func (mjp *MultipleJSONPath) String() string
- type SingleJSONPath
- func (jp *SingleJSONPath) FieldName() string
- func (jp *SingleJSONPath) Get(obj map[string]interface{}) (interface{}, bool)
- func (jp *SingleJSONPath) GetAndRemove(obj map[string]interface{}) (interface{}, bool)
- func (jp *SingleJSONPath) IsEmpty() bool
- func (jp *SingleJSONPath) Set(obj map[string]interface{}, value interface{}) error
- func (jp *SingleJSONPath) SetIfNotExist(obj map[string]interface{}, value interface{}) error
- func (jp *SingleJSONPath) SetOrMergeIfExist(obj map[string]interface{}, values map[string]interface{}) error
- func (jp *SingleJSONPath) String() string
Constants ¶
This section is empty.
Variables ¶
var ErrNodeNotExist = errors.New("Inner node doesn't exist")
Functions ¶
func JsonEscape ¶
func Merge ¶
Merge puts all keys from the right map into the left map with deep overwriting returns merged map result
func UnmarshalConfig ¶
func UnmarshalConfig(config interface{}, object interface{}) error
UnmarshalConfig serializes and deserializes config into the object return error if occurred
Types ¶
type JSONPath ¶
type JSONPath interface { IsEmpty() bool Get(obj map[string]interface{}) (interface{}, bool) GetAndRemove(obj map[string]interface{}) (interface{}, bool) Set(obj map[string]interface{}, value interface{}) error SetIfNotExist(obj map[string]interface{}, value interface{}) error SetOrMergeIfExist(obj map[string]interface{}, values map[string]interface{}) error String() string FieldName() string }
func NewJSONPath ¶
NewJSONPath return JSONPath (Single or Multiple)
type JSONPaths ¶
type JSONPaths struct {
// contains filtered or unexported fields
}
JSONPaths supports several JSON paths Map:
"key1/key2/key3" -> JSONPath: [key1, key2, key3] "key4/key5/key6" -> JSONPath: [key4, key5, key6] "key7/key8/key9" -> JSONPath: [key7, key8, key9]
func NewJSONPaths ¶
NewJSONPaths parses configuration settings and returns map of parsed recognition nodes
func (*JSONPaths) Get ¶
Get returns values from event according to configuration settings Map:
"key1/key2/key3" -> value1 "key4/key5/key6" -> value2 "key7/key8/key9" -> value3
type MultipleJSONPath ¶
type MultipleJSONPath struct {
// contains filtered or unexported fields
}
MultipleJSONPath is a struct for extracting and setting value by JSON paths with extended syntax /key1/key2||/key3/key4
func NewMultipleJSONPath ¶
func NewMultipleJSONPath(paths []string) *MultipleJSONPath
NewMultipleJSONPath returns MultipleJSONPath instance
func (*MultipleJSONPath) FieldName ¶
func (mjp *MultipleJSONPath) FieldName() string
FieldName returns string representation of first JSON path
func (*MultipleJSONPath) Get ¶
func (mjp *MultipleJSONPath) Get(obj map[string]interface{}) (interface{}, bool)
Get returns first json path non empty result
func (*MultipleJSONPath) GetAndRemove ¶
func (mjp *MultipleJSONPath) GetAndRemove(obj map[string]interface{}) (interface{}, bool)
GetAndRemove returns first json path non empty result and remove it from origin json
func (*MultipleJSONPath) IsEmpty ¶
func (mjp *MultipleJSONPath) IsEmpty() bool
IsEmpty returns true if all paths are empty
func (*MultipleJSONPath) Set ¶
func (mjp *MultipleJSONPath) Set(obj map[string]interface{}, value interface{}) error
Set puts value to first json path that exists:
{key1:"abc", key2:"qwe"} /key1/key3 -> not set {key1:{key2: {key3: "qwe"}}} /key1/key3 -> not set {key1:{key2: {key3: "qwe"}}} /key1/key2 -> set ok {key1:{}} /key1/key2 -> set ok {} /key1 -> set ok
returns err if value wasn't set
func (*MultipleJSONPath) SetIfNotExist ¶
func (mjp *MultipleJSONPath) SetIfNotExist(obj map[string]interface{}, value interface{}) error
SetIfNotExist puts value into the object only if JSON path doesn't exist in other words the func DOESN'T overwrite the key with input value {key1:"abc", key2:"qwe"} /key1/key2 -> not set {key1:"abc", key2:"qwe"} /key1/key3 -> set
func (*MultipleJSONPath) SetOrMergeIfExist ¶
func (mjp *MultipleJSONPath) SetOrMergeIfExist(obj map[string]interface{}, values map[string]interface{}) error
SetOrMergeIfExist puts value into the object if JSON path doesn't exist if JSON path exist and is a map than all values will be merged separately {key1:"abc", key2:"qwe"} /key1/key3 -> set {key1:"abc", key2:{key3:"qwe"}} /key1/key2 -> merge
func (*MultipleJSONPath) String ¶
func (mjp *MultipleJSONPath) String() string
String returns string representation of JSON path (/key1/key2)
type SingleJSONPath ¶
type SingleJSONPath struct {
// contains filtered or unexported fields
}
SingleJSONPath is a struct for extracting and setting value by JSON path
func NewSingleJSONPath ¶
func NewSingleJSONPath(path string) *SingleJSONPath
NewSingleJSONPath return Single JSONPath (Single or Multiple)
func (*SingleJSONPath) FieldName ¶
func (jp *SingleJSONPath) FieldName() string
FieldName returns string representation of flat field (key1_key2)
func (*SingleJSONPath) Get ¶
func (jp *SingleJSONPath) Get(obj map[string]interface{}) (interface{}, bool)
Get returns value of json path
func (*SingleJSONPath) GetAndRemove ¶
func (jp *SingleJSONPath) GetAndRemove(obj map[string]interface{}) (interface{}, bool)
GetAndRemove returns value of json path and remove it from origin json
func (*SingleJSONPath) IsEmpty ¶
func (jp *SingleJSONPath) IsEmpty() bool
IsEmpty returns true if path is empty
func (*SingleJSONPath) Set ¶
func (jp *SingleJSONPath) Set(obj map[string]interface{}, value interface{}) error
Set put value to json path with creating inner objects assume that obj can't be nil return err if value wasn't set
func (*SingleJSONPath) SetIfNotExist ¶
func (jp *SingleJSONPath) SetIfNotExist(obj map[string]interface{}, value interface{}) error
SetIfNotExist puts value into the object only if JSON path doesn't exist in other words DOESN'T overwrite key {key1:"abc", key2:"qwe"} /key1/key3 -> set {key1:"abc", key2:"qwe"} /key1/key2 -> not set
func (*SingleJSONPath) SetOrMergeIfExist ¶
func (jp *SingleJSONPath) SetOrMergeIfExist(obj map[string]interface{}, values map[string]interface{}) error
SetOrMergeIfExist puts value into the object if JSON path doesn't exist if JSON path exist and is a map than all values will be merged separately {key1:"abc", key2:"qwe"} /key1/key3 -> set {key1:"abc", key2:{key3:"qwe"}} /key1/key2 -> merge
func (*SingleJSONPath) String ¶
func (jp *SingleJSONPath) String() string
String returns string representation of JSON path (/key1/key2)