fix (concurrency): fix concurrency problem

This commit is contained in:
Mickael KERJEAN
2019-02-25 17:41:47 +11:00
parent 14e177026d
commit c9c3a9f5e2
4 changed files with 16 additions and 48 deletions

View File

@ -3,7 +3,6 @@ package common
import (
"bytes"
"encoding/json"
"sync"
)
func NewBool(t bool) *bool {
@ -67,30 +66,3 @@ func PrettyPrint(json_dirty []byte) []byte {
json_pretty.Write([]byte("\n"))
return json_pretty.Bytes()
}
type SafeMapStringString struct {
sync.RWMutex
internal map[string]string
}
func NewSafeMapStringString() SafeMapStringString {
return SafeMapStringString{
internal: make(map[string]string),
}
}
func(this SafeMapStringString) Set(key string, value string) {
this.Lock()
this.internal[key] = value
this.Unlock()
}
func(this SafeMapStringString) Gets(keys ...string) []string{
this.RLock()
res := make([]string, len(keys))
for i, key := range keys {
res[i] = this.internal[key]
}
this.RUnlock()
return res
}