1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
values.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.0.0-alpha2

搜索帮助