smap

package
v2.0.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldsKey = "fields"
	TagsKey   = "tags"
)

Event metadata constants. These keys are used within libbeat to identify metadata stored in an event.

Variables

View Source
var (
	// ErrKeyNotFound indicates that the specified key was not found.
	ErrKeyNotFound = errors.New("key not found")
)

Functions

func AddTags

func AddTags(ms StringMap, tags []string) error

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

func AddTagsWithKey(ms StringMap, key string, tags []string) error

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

func MergeFields(target, from StringMap, underRoot bool) error

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

func MergeFieldsDeep(target, from StringMap, underRoot bool) error

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

func MapStrUnion(dict1 StringMap, dict2 StringMap) StringMap

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

func (m StringMap) Clone() StringMap

Clone returns a copy of the MapStr. It recursively makes copies of inner maps.

func (StringMap) CopyFieldsTo

func (m StringMap) CopyFieldsTo(to StringMap, key string) error

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

func (m StringMap) DeepUpdate(d StringMap)

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

func (m StringMap) DeepUpdateNoOverwrite(d StringMap)

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) Delete

func (m StringMap) Delete(key string) error

Delete deletes the given key from the map.

func (StringMap) Flatten

func (m StringMap) Flatten() StringMap

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) Get

func (m StringMap) Get(key string) (interface{}, error)

Get 获取值

func (StringMap) HasKey

func (m StringMap) HasKey(key string) (bool, error)

HasKey 获取key

func (StringMap) Put

func (m StringMap) Put(key string, value interface{}) (interface{}, error)

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) Scan

func (m *StringMap) Scan(value interface{}) error

Scan todo

func (StringMap) String

func (m StringMap) String() string

String returns the MapStr as JSON.

func (StringMap) StringToPrint

func (m StringMap) StringToPrint() string

StringToPrint returns the MapStr as pretty JSON.

func (StringMap) Update

func (m StringMap) Update(d StringMap)

Update copies all the key-value pairs from d to this map. If the key already exists then it is overwritten. This method does not merge nested maps.

func (StringMap) Value

func (m StringMap) Value() (driver.Value, error)

Value todo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL