mirror of
https://gitee.com/johng/gf
synced 2026-07-07 14:25:17 +08:00
ghttp增加Init&Shut回调函数注册功能,gmap增加SetWithDefault方法
This commit is contained in:
@ -60,13 +60,25 @@ func (this *InterfaceInterfaceMap) BatchSet(m map[interface{}]interface{}) {
|
||||
}
|
||||
|
||||
// 获取键值
|
||||
func (this *InterfaceInterfaceMap) Get(key interface{}) (interface{}) {
|
||||
func (this *InterfaceInterfaceMap) Get(key interface{}) interface{} {
|
||||
this.mu.RLock()
|
||||
val, _ := this.m[key]
|
||||
this.mu.RUnlock()
|
||||
return val
|
||||
}
|
||||
|
||||
// 获取键值,如果键值不存在则写入默认值
|
||||
func (this *InterfaceInterfaceMap) GetWithDefault(key interface{}, value interface{}) interface{} {
|
||||
this.mu.Lock()
|
||||
val, ok := this.m[key]
|
||||
if !ok {
|
||||
this.m[key] = value
|
||||
val = value
|
||||
}
|
||||
this.mu.Unlock()
|
||||
return val
|
||||
}
|
||||
|
||||
func (this *InterfaceInterfaceMap) GetBool(key interface{}) bool {
|
||||
return gconv.Bool(this.Get(key))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user