summaryrefslogtreecommitdiff
path: root/system/db/config.go
diff options
context:
space:
mode:
authorSteve <nilslice@gmail.com>2016-12-19 11:19:53 -0800
committerGitHub <noreply@github.com>2016-12-19 11:19:53 -0800
commit3791fadda7b761ffba38c567da29e2e71acd1dfb (patch)
tree79d810f9aafa1868ee0760983937470d0eea3db8 /system/db/config.go
parentb20c5bdee38682edc851e646d815a34689c3c923 (diff)
[addons] Creating foundation for plugin-like system "Addons" (#24)
* adding addons dir and sample addon which enables the use of a new input element in forms for referencing other content. "addons" is a conceptual plugin-like feature, similar to wordpress "plugins" dir, but not as sophisticated
Diffstat (limited to 'system/db/config.go')
-rw-r--r--system/db/config.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/system/db/config.go b/system/db/config.go
index b5a07e4..4bbf29b 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -3,6 +3,7 @@ package db
import (
"bytes"
"encoding/json"
+ "fmt"
"net/url"
"strings"
@@ -117,7 +118,50 @@ 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
+ }
+
+ // set k/v from params to decoded map
+ kv[key] = value
+
+ 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 {
+ data.Add(k, vv[i])
+ }
+
+ default:
+ data.Set(k, fmt.Sprintf("%v", v))
+ }
+ }
+
+ 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)
}