From 50500b9e8eb0b891f598e66801f5dcca55d1186e Mon Sep 17 00:00:00 2001 From: hanemile Date: Sun, 19 Jul 2020 13:15:31 +0200 Subject: src update --- src/main.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main.go (limited to 'src/main.go') diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..ecb400e --- /dev/null +++ b/src/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "fmt" + "strings" + + "git.darknebu.la/chaosdorf/freitagsfoo/src/db" + "github.com/sirupsen/logrus" + "github.com/spf13/viper" +) + +func main() { + initConfig() + initLogging() + + pgdb := db.Connect() + defer db.Disconnect(pgdb) + + initDB(pgdb) + + initHTTPServer() +} + +func initConfig() { + logrus.Info("Init config") + + viper.SetConfigName("config") + viper.AddConfigPath(".") + viper.AddConfigPath("/go/src/app/") + viper.AutomaticEnv() + + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + + err := viper.ReadInConfig() + if err != nil { + panic(fmt.Errorf("Fatal error config file: %s", err)) + } + + // var conf structs.Configuration + // err = viper.Unmarshal(&conf) + // if err != nil { + // log.Fatal("unable to decode into struct: %v", err) + // } +} + +func initLogging() { + logrus.Info("Init logging") + 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) + } +} -- cgit 1.4.1