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

@ -66,6 +66,18 @@ func (this *StringStringMap) Get(key string) string {
return val
}
// 获取键值,如果键值不存在则写入默认值
func (this *StringStringMap) GetWithDefault(key string, value string) string {
this.mu.Lock()
val, ok := this.m[key]
if !ok {
this.m[key] = value
val = value
}
this.mu.Unlock()
return val
}
// 删除键值对
func (this *StringStringMap) Remove(key string) {
this.mu.Lock()