2017-02-16 03:02:13 +00:00
|
|
|
package config
|
|
|
|
|
2017-02-16 03:49:41 +00:00
|
|
|
// defaults
|
2017-02-16 03:02:13 +00:00
|
|
|
var switches = []*Switch{
|
|
|
|
&Switch{
|
2017-02-16 03:49:41 +00:00
|
|
|
key: "sortReversed",
|
2017-02-16 03:02:13 +00:00
|
|
|
val: false,
|
|
|
|
label: "Reverse Sort Order",
|
|
|
|
},
|
|
|
|
&Switch{
|
|
|
|
key: "allContainers",
|
|
|
|
val: false,
|
|
|
|
label: "Show All Containers",
|
|
|
|
},
|
|
|
|
&Switch{
|
|
|
|
key: "enableHeader",
|
|
|
|
val: false,
|
|
|
|
label: "Enable cTop Status Line",
|
|
|
|
},
|
|
|
|
&Switch{
|
|
|
|
key: "loggingEnabled",
|
|
|
|
val: true,
|
|
|
|
label: "Enable Logging Server",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
type Switch struct {
|
|
|
|
key string
|
|
|
|
val bool
|
|
|
|
label string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return toggle value
|
|
|
|
func GetSwitch(k string) bool {
|
2017-02-16 03:49:41 +00:00
|
|
|
for _, sw := range GlobalSwitches {
|
|
|
|
if sw.key == k {
|
|
|
|
return sw.val
|
|
|
|
}
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|
|
|
|
return false // default
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle a boolean switch
|
|
|
|
func Toggle(k string) {
|
2017-02-16 03:49:41 +00:00
|
|
|
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)
|
2017-02-16 03:02:13 +00:00
|
|
|
}
|