mirror of
https://gitee.com/johng/gf
synced 2026-07-04 13:02:36 +08:00
ghttp增加Init&Shut回调函数注册功能,gmap增加SetWithDefault方法
This commit is contained in:
@ -67,6 +67,18 @@ func (this *StringInterfaceMap) Get(key string) interface{} {
|
||||
return val
|
||||
}
|
||||
|
||||
// 获取键值,如果键值不存在则写入默认值
|
||||
func (this *StringInterfaceMap) GetWithDefault(key string, 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 *StringInterfaceMap) GetBool(key string) bool {
|
||||
return gconv.Bool(this.Get(key))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user