ghttp增加Init&Shut回调函数注册功能,gmap增加SetWithDefault方法

This commit is contained in:
John
2018-03-13 17:57:41 +08:00
parent 1ffecb4dc1
commit 9e8c3c631f
18 changed files with 337 additions and 47 deletions

View File

@ -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))
}