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

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

View File

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