ctop/config/main.go
Bradley Cicenas 8aa932b29f Toggle debug mode via env var
remove logging param from global config, allowing logging server and
level to be configured inside logging subpackage from CTOP_DEBUG env var
2017-03-19 15:10:03 +10:00

39 lines
714 B
Go

package config
import (
"fmt"
"os"
"github.com/bcicen/ctop/logging"
)
var (
GlobalParams []*Param
GlobalSwitches []*Switch
log = logging.Init()
)
func Init() {
for _, p := range params {
GlobalParams = append(GlobalParams, p)
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
}
for _, s := range switches {
GlobalSwitches = append(GlobalSwitches, s)
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
}
}
func quote(s string) string {
return fmt.Sprintf("\"%s\"", s)
}
// Return env var value if set, else return defaultVal
func getEnv(key, defaultVal string) string {
val := os.Getenv(key)
if val != "" {
return val
}
return defaultVal
}