package main import ( "fmt" "log" "net/http" "strings" "git.darknebu.la/emile/corona-metrics/src/structs" "github.com/sirupsen/logrus" "github.com/spf13/viper" ) func main() { initConfig() initLogging() go ExitHandler() http.Serve() } // initialize the config (config.yml) func initConfig() { // parse the config viper.SetConfigName("config") viper.AddConfigPath(".") viper.AutomaticEnv() // Fix nested keys don't work with . viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // read the config err := viper.ReadInConfig() if err != nil { panic(fmt.Errorf("Fatal error config file: %s", err)) } // unmarshal the config var conf structs.Configuration err = viper.Unmarshal(&conf) if err != nil { log.Fatalf("unable to decode into struct, %v", err) } } // Initialize the loglevel using the value given in the config func initLogging() { switch viper.GetString("verbose.level") { case "1": logrus.SetLevel(logrus.PanicLevel) case "2": logrus.SetLevel(logrus.FatalLevel) case "3": logrus.SetLevel(logrus.ErrorLevel) case "4": logrus.SetLevel(logrus.WarnLevel) case "5": logrus.SetLevel(logrus.InfoLevel) case "6": logrus.SetLevel(logrus.DebugLevel) case "7": logrus.SetLevel(logrus.TraceLevel) } }