simplify config, export GlobalParams+GlobalSwitches

This commit is contained in:
Bradley Cicenas
2017-02-16 03:49:41 +00:00
parent 90f6ce3962
commit 5bbce31601
4 changed files with 42 additions and 45 deletions

View File

@@ -1,8 +1,9 @@
package config
// defaults
var switches = []*Switch{
&Switch{
key: "sortReverse",
key: "sortReversed",
val: false,
label: "Reverse Sort Order",
},
@@ -31,14 +32,23 @@ type Switch struct {
// Return toggle value
func GetSwitch(k string) bool {
if _, ok := Global.switches[k]; ok == true {
return Global.switches[k].val
for _, sw := range GlobalSwitches {
if sw.key == k {
return sw.val
}
}
return false // default
}
// Toggle a boolean switch
func Toggle(k string) {
Global.switches[k].val = Global.switches[k].val != true
log.Noticef("config change: %s: %t", k, Global.switches[k].val)
for _, sw := range GlobalSwitches {
if sw.key == k {
newVal := sw.val != true
log.Noticef("config change: %s: %t -> %t", k, sw.val, newVal)
sw.val = newVal
return
}
}
log.Errorf("ignoring toggle for non-existant switch: %s", k)
}