Documentation ¶
Index ¶
- Constants
- Variables
- func AddTags(ms StringMap, tags []string) error
- func AddTagsWithKey(ms StringMap, key string, tags []string) error
- func MergeFields(target, from StringMap, underRoot bool) error
- func MergeFieldsDeep(target, from StringMap, underRoot bool) error
- type StringMap
- func (m StringMap) Clone() StringMap
- func (m StringMap) CopyFieldsTo(to StringMap, key string) error
- func (m StringMap) DeepUpdate(d StringMap)
- func (m StringMap) DeepUpdateNoOverwrite(d StringMap)
- func (m StringMap) Delete(key string) error
- func (m StringMap) Flatten() StringMap
- func (m StringMap) Get(key string) (interface{}, error)
- func (m StringMap) HasKey(key string) (bool, error)
- func (m StringMap) Put(key string, value interface{}) (interface{}, error)
- func (m *StringMap) Scan(value interface{}) error
- func (m StringMap) String() string
- func (m StringMap) StringToPrint() string
- func (m StringMap) Update(d StringMap)
- func (m StringMap) Value() (driver.Value, error)
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 MapStr 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 MapStr.
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 MapStr.
Types ¶
type StringMap ¶
type StringMap map[string]interface{}
StringMap map参数
func MapStrUnion ¶
MapStrUnion creates a new MapStr 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 (StringMap) Clone ¶
Clone returns a copy of the MapStr. It recursively makes copies of inner maps.
func (StringMap) 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 (StringMap) 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 (StringMap) 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 (StringMap) Flatten ¶
Flatten flattens the given MapStr and returns a flat MapStr.
Example:
"hello": MapStr{"world": "test" }
This is converted to:
"hello.world": "test"
This can be useful for testing or logging.
func (StringMap) 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 (StringMap) StringToPrint ¶
StringToPrint returns the MapStr as pretty JSON.