1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
registry.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
package cfgfile
import "sync"
// Registry holds a list of Runners mapped by their unique hashes
type Registry struct {
sync.RWMutex
List map[uint64]Runner
}
// NewRegistry returns a new empty Registry
func NewRegistry() *Registry {
return &Registry{
List: map[uint64]Runner{},
}
}
// Add the given Runner to the list, indexed by a hash
func (r *Registry) Add(hash uint64, m Runner) {
r.Lock()
defer r.Unlock()
r.List[hash] = m
}
// Remove the Runner with the given hash from the list
func (r *Registry) Remove(hash uint64) {
r.Lock()
defer r.Unlock()
delete(r.List, hash)
}
// Has returns true if there is a Runner with the given hash
func (r *Registry) Has(hash uint64) bool {
r.RLock()
defer r.RUnlock()
_, ok := r.List[hash]
return ok
}
// Get returns the Runner with the given hash, or nil if it doesn't exist
func (r *Registry) Get(hash uint64) Runner {
r.RLock()
defer r.RUnlock()
return r.List[hash]
}
// CopyList returns a static copy of the Runners map
func (r *Registry) CopyList() map[uint64]Runner {
r.RLock()
defer r.RUnlock()
// Create a copy of the list
list := map[uint64]Runner{}
for k, v := range r.List {
list[k] = v
}
return list
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.0

搜索帮助