37 lines
643 B
Go
37 lines
643 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func Init() *Config {
|
|
cfg := New()
|
|
|
|
cfgInfo, err := getStructInfo(cfg)
|
|
if err != nil {
|
|
cfg.Log.Error("Unable to initialize program parameters", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// get command line flags
|
|
cfg.parseFlags(cfgInfo)
|
|
|
|
// set logging Level
|
|
setLogLevel(cfg)
|
|
|
|
// set timezone & time format
|
|
cfg.TZUTC, _ = time.LoadLocation("UTC")
|
|
cfg.TZLocal, err = time.LoadLocation(cfg.TimeZoneLocal)
|
|
if err != nil {
|
|
cfg.Log.Error("Unable to parse timezone string", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// print running config
|
|
printRunningConfig(cfg, cfgInfo)
|
|
|
|
// return configuration
|
|
return cfg
|
|
}
|