Enable ability to flip configuration of allownomutate
This commit is contained in:
@@ -41,8 +41,8 @@ type Config struct {
|
||||
}
|
||||
|
||||
// DefaultConfig initializes the config variable for use with a prepared set of defaults.
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
Log: &logutils.LevelFilter{
|
||||
Levels: []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARNING", "ERROR"},
|
||||
Writer: os.Stderr,
|
||||
@@ -50,7 +50,7 @@ func DefaultConfig() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
func (cfg *Config) setLogLevel() {
|
||||
func setLogLevel(cfg Config) {
|
||||
switch {
|
||||
case cfg.LogLevel <= 20:
|
||||
cfg.Log.SetMinLevel(logutils.LogLevel("ERROR"))
|
||||
@@ -66,7 +66,7 @@ func (cfg *Config) setLogLevel() {
|
||||
log.SetOutput(cfg.Log)
|
||||
}
|
||||
|
||||
func (cfg *Config) printRunningConfig(cfgInfo []StructInfo) {
|
||||
func printRunningConfig(cfg *Config, cfgInfo []StructInfo) {
|
||||
log.Printf("[DEBUG] Current Running Configuration Values:")
|
||||
for _, info := range cfgInfo {
|
||||
switch info.Type.String() {
|
||||
|
@@ -19,10 +19,10 @@ func getOSEnv(env, def string) string {
|
||||
// Init initializes the application configuration by reading default values from the struct's tags
|
||||
// and environment variables. Tags processed by this process are as follows:
|
||||
// `ignored:"true" env:"ENVIRONMENT_VARIABLE" default:"default value"`
|
||||
func Init() *Config {
|
||||
func Init() Config {
|
||||
cfg := DefaultConfig()
|
||||
|
||||
cfgInfo, err := getStructInfo(cfg)
|
||||
cfgInfo, err := getStructInfo(&cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] %v", err)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func Init() *Config {
|
||||
if info.DefaultValue != nil {
|
||||
dv = info.DefaultValue.(string)
|
||||
}
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*string)
|
||||
p := reflect.ValueOf(&cfg).Elem().FieldByName(info.Name).Addr().Interface().(*string)
|
||||
flag.StringVar(p, info.Name, dv, "("+info.Key+")")
|
||||
|
||||
case "bool":
|
||||
@@ -42,7 +42,7 @@ func Init() *Config {
|
||||
if info.DefaultValue != nil {
|
||||
dv = info.DefaultValue.(bool)
|
||||
}
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*bool)
|
||||
p := reflect.ValueOf(&cfg).Elem().FieldByName(info.Name).Addr().Interface().(*bool)
|
||||
flag.BoolVar(p, info.Name, dv, "("+info.Key+")")
|
||||
|
||||
case "int":
|
||||
@@ -50,14 +50,14 @@ func Init() *Config {
|
||||
if info.DefaultValue != nil {
|
||||
dv = int(info.DefaultValue.(int64))
|
||||
}
|
||||
p := reflect.ValueOf(cfg).Elem().FieldByName(info.Name).Addr().Interface().(*int)
|
||||
p := reflect.ValueOf(&cfg).Elem().FieldByName(info.Name).Addr().Interface().(*int)
|
||||
flag.IntVar(p, info.Name, dv, "("+info.Key+")")
|
||||
}
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
// set logging level
|
||||
cfg.setLogLevel()
|
||||
setLogLevel(cfg)
|
||||
|
||||
// timezone & format configuration
|
||||
cfg.TZoneUTC, _ = time.LoadLocation("UTC")
|
||||
@@ -71,7 +71,7 @@ func Init() *Config {
|
||||
time.Now().Format(cfg.TimeFormat)
|
||||
|
||||
// print running config
|
||||
cfg.printRunningConfig(cfgInfo)
|
||||
printRunningConfig(&cfg, cfgInfo)
|
||||
|
||||
// read config file
|
||||
configFileData, err := getConfigFileData(cfg.ConfigFile)
|
||||
|
Reference in New Issue
Block a user