summaryrefslogtreecommitdiff
path: root/system/db/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'system/db/config.go')
-rw-r--r--system/db/config.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/system/db/config.go b/system/db/config.go
index b5a07e4..ef3c382 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -117,7 +117,47 @@ func ConfigAll() ([]byte, error) {
return val.Bytes(), nil
}
+// PutConfig updates a single k/v in the config
+func PutConfig(key string, value interface{}) error {
+ kv := make(map[string]interface{})
+
+ c, err := ConfigAll()
+ if err != nil {
+ return err
+ }
+
+ err = json.Unmarshal(c, &kv)
+ if err != nil {
+ return err
+ }
+
+ data := make(url.Values)
+ for k, v := range kv {
+ switch v.(type) {
+ case string:
+ data.Set(k, v.(string))
+ case []string:
+ vv := v.([]string)
+ for i := range vv {
+ if i == 0 {
+ data.Set(k, vv[i])
+ } else {
+ data.Add(k, vv[i])
+ }
+ }
+ }
+ }
+
+ err = SetConfig(data)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
// ConfigCache is a in-memory cache of the Configs for quicker lookups
+// 'key' is the JSON tag associated with the config field
func ConfigCache(key string) string {
return configCache.Get(key)
}