Documentation ¶
Index ¶
- Constants
- Variables
- func AddTags(ms M, tags []string) error
- func AddTagsWithKey(ms M, key string, tags []string) error
- func MergeFields(target, from M, underRoot bool) error
- func MergeFieldsDeep(target, from M, underRoot bool) error
- type EventMetadata
- type M
- func (m M) Clone() M
- func (m M) CopyFieldsTo(to M, key string) error
- func (m M) DeepUpdate(d M)
- func (m M) DeepUpdateNoOverwrite(d M)
- func (m M) Delete(key string) error
- func (m M) Flatten() M
- func (m M) FlattenKeys() *[]string
- func (m M) Format(f fmt.State, c rune)
- func (m M) GetValue(key string) (interface{}, error)
- func (m M) HasKey(key string) (bool, error)
- func (m M) MarshalLogObject(enc zapcore.ObjectEncoder) error
- func (m M) Put(key string, value interface{}) (interface{}, error)
- func (m M) String() string
- func (m M) StringToPrint() string
- func (m M) Update(d M)
- type Pointer
Constants ¶
const ( FieldsKey = "fields" TagsKey = "tags" )
Event metadata constants. These keys are used within libbeat to identify metadata stored in an event.
Variables ¶
var ( // ErrKeyNotFound indicates that the specified key was not found. ErrKeyNotFound = errors.New("key not found") )
Functions ¶
func AddTags ¶
AddTags appends a tag to the tags field of ms. If the tags field does not exist then it will be created. If the tags field exists and is not a []string then an error will be returned. It does not deduplicate the list of tags.
func AddTagsWithKey ¶
AddTagsWithKey appends a tag to the key field of ms. If the field does not exist then it will be created. If the field exists and is not a []string then an error will be returned. It does not deduplicate the list.
func MergeFields ¶
MergeFields merges the top-level keys and values in each source map (it does not perform a deep merge). If the same key exists in both, the value in fields takes precedence. If underRoot is true then the contents of the fields M is merged with the value of the 'fields' key in target.
An error is returned if underRoot is true and the value of ms.fields is not a M.
func MergeFieldsDeep ¶
MergeFieldsDeep recursively merges the keys and values from `from` into `target`, either into ms itself (if underRoot == true) or into ms["fields"] (if underRoot == false). If the same key exists in `from` and the destination map, the value in fields takes precedence.
An error is returned if underRoot is true and the value of ms["fields"] is not a M.
Types ¶
type EventMetadata ¶
type EventMetadata struct { Fields M FieldsUnderRoot bool `config:"fields_under_root"` Tags []string }
EventMetadata contains fields and tags that can be added to an event via configuration.
type M ¶
type M map[string]interface{}
M is a map[string]interface{} wrapper with utility methods for common map operations like converting to JSON.
func Union ¶
Union creates a new M containing the union of the key-value pairs of the two maps. If the same key is present in both, the key-value pairs from dict2 overwrite the ones from dict1.
func (M) CopyFieldsTo ¶
CopyFieldsTo copies the field specified by key to the given map. It will overwrite the key if it exists. An error is returned if the key does not exist in the source map.
func (M) DeepUpdate ¶
DeepUpdate recursively copies the key-value pairs from d to this map. If the key is present and a map as well, the sub-map will be updated recursively via DeepUpdate. DeepUpdateNoOverwrite is a version of this function that does not overwrite existing values.
func (M) DeepUpdateNoOverwrite ¶
DeepUpdateNoOverwrite recursively copies the key-value pairs from d to this map. If a key is already present it will not be overwritten. DeepUpdate is a version of this function that overwrites existing values.
func (M) Flatten ¶
Flatten flattens the given M and returns a flat M.
Example:
"hello": M{"world": "test" }
This is converted to:
"hello.world": "test"
This can be useful for testing or logging.
func (M) FlattenKeys ¶ added in v0.2.3
FlattenKeys flattens given MapStr keys and returns a containing array pointer
Example:
"hello": MapStr{"world": "test" }
This is converted to:
["hello.world"]
func (M) GetValue ¶
GetValue gets a value from the map. If the key does not exist then an error is returned.
func (M) HasKey ¶
HasKey returns true if the key exist. If an error occurs then false is returned with a non-nil error.
func (M) MarshalLogObject ¶
func (m M) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements the zapcore.ObjectMarshaler interface and allows for more efficient marshaling of mapstr.M in structured logging.
func (M) Put ¶
Put associates the specified value with the specified key. If the map previously contained a mapping for the key, the old value is replaced and returned. The key can be expressed in dot-notation (e.g. x.y) to put a value into a nested map.
If you need insert keys containing dots then you must use bracket notation to insert values (e.g. m[key] = value).
func (M) StringToPrint ¶
StringToPrint returns the M as pretty JSON.
type Pointer ¶
type Pointer struct {
// contains filtered or unexported fields
}
Pointer stores a pointer to atomically get/set a mapstr.M object This should give faster access for use cases with lots of reads and a few changes. It's important to note that modifying the map is not thread safe, only fully replacing it.
func NewPointer ¶
NewMPointer initializes and returns a pointer to the given M