2024-07-11 14:12:22 -05:00

39 lines
701 B
Go

package config
import (
"log"
"os"
"time"
)
func Init() Config {
cfg := New()
cfgInfo, err := getStructInfo(&cfg)
if err != nil {
log.Fatalf("Unable to initialize program: %v", err)
}
// get command line flags
if err := cfg.parseFlags(cfgInfo); err != nil {
log.Fatalf("Unable to initialize program: %v", err)
}
// 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
}