1 Star 1 Fork 3

menuiis/gkit

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
meta.go 714 Bytes
Copy Edit Raw Blame History
SongZhibin97 authored 2022-01-19 11:14 +08:00 . feat:规范命名&json优化
package task
import "sync"
// Meta task可以携带元信息
type Meta struct {
meta map[string]interface{}
sync.RWMutex
safe bool
}
// NewMeta 生成meta信息
func NewMeta(safe bool) *Meta {
return &Meta{
meta: make(map[string]interface{}),
safe: safe,
}
}
// Set 如果存在会覆盖
func (m *Meta) Set(key string, value interface{}) {
if m.safe {
m.Lock()
defer m.Unlock()
}
m.meta[key] = value
}
func (m *Meta) Get(key string) (interface{}, bool) {
if m.safe {
m.RLock()
defer m.RUnlock()
}
v, ok := m.meta[key]
return v, ok
}
func (m *Meta) Range(f func(key string, value interface{})) {
if m.safe {
m.Lock()
defer m.Unlock()
}
for k, v := range m.meta {
f(k, v)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
d3f65ed26d21

Search