add communicator api

This commit is contained in:
hebo
2019-09-05 20:27:49 +08:00
parent d06ca1131e
commit c9f514feed
18 changed files with 1490 additions and 42 deletions

View File

@@ -0,0 +1,27 @@
package communicator
import "fmt"
// SetConfig set config by config key(name) and value
func SetConfig(key string, val interface{}) (err error) {
configMapLock.Lock()
defer configMapLock.Unlock()
config, ok := configMap[key]
if !ok {
err = fmt.Errorf("no config %s exist", key)
return
}
err = config.setVal(val)
return
}
// GetConfig get config value by config key(name)
func GetConfig(key string) (val interface{}) {
configMapLock.RLock()
defer configMapLock.RUnlock()
config := configMap[key]
return config.getVal()
}