1 Star 0 Fork 0

zhangjungang/beats

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
values.go 1.48 KB
Copy Edit Raw Blame History
package outputs
import "github.com/elastic/beats/libbeat/common"
// Values is a recursive key/value store for use by output plugins and publisher
// pipeline to share context-dependent values.
type Values struct {
parent *Values
key, value interface{}
}
// ValueWith creates new key/value store shadowing potentially old keys.
func ValueWith(parent *Values, key interface{}, value interface{}) *Values {
return &Values{
parent: parent,
key: key,
value: value,
}
}
// Append creates new key/value store from existing store by adding a new
// key/value pair potentially shadowing an already present key/value pair.
func (v *Values) Append(key, value interface{}) *Values {
if v.IsEmpty() {
return ValueWith(nil, key, value)
}
return ValueWith(v, key, value)
}
// IsEmpty returns true if key/value store is empty.
func (v *Values) IsEmpty() bool {
return v == nil || (v.parent == nil && v.key == nil && v.value == nil)
}
// Get retrieves a value for the given key.
func (v *Values) Get(key interface{}) (interface{}, bool) {
if v == nil {
return nil, false
}
if v.key == key {
return v.value, true
}
return v.parent.Get(key)
}
// standard outputs values utilities
type keyMetadata int
func ValuesWithMetadata(parent *Values, meta common.MapStr) *Values {
return parent.Append(keyMetadata(0), meta)
}
func GetMetadata(v *Values) common.MapStr {
value, ok := v.Get(keyMetadata(0))
if !ok {
return nil
}
if m, ok := value.(common.MapStr); ok {
return m
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v5.4.3

Search