diff options
| author | Max | 2018-02-06 00:35:39 +0100 |
|---|---|---|
| committer | Max | 2018-02-06 00:35:39 +0100 |
| commit | 71950479fbd6088f249e5fda3b180f294d1d745d (patch) | |
| tree | 06f360a7e02b7e0011bda815fa102ec54ae8d0ec /config.go | |
| parent | 13a807854bf4d0258723ec3152b217ed4cf8e051 (diff) | |
| download | alkobote-71950479fbd6088f249e5fda3b180f294d1d745d.tar.gz | |
Moves crawler to designated directory.
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/config.go b/config.go deleted file mode 100644 index 2706201..0000000 --- a/config.go +++ /dev/null @@ -1,76 +0,0 @@ -package main - -import ( - log "github.com/Sirupsen/logrus" - "github.com/spf13/viper" -) - -type Config struct { - DBDriver string - DBDBName string - DBHost string - DBPort string - DBUser string - DBPassword string - DBOptions string - DBPath string // for sqlite - - Debug bool -} - -// Parses the configuration and sets the configuration struct. -func (c *Config) parseConfig(configFile string) { - - viper.SetDefault("DBDriver", "mysql") - viper.SetDefault("DBDBName", "alkobote") - viper.SetDefault("DBHost", "localhost") - viper.SetDefault("DBPort", "3306") - - viper.SetDefault("DBPath", "./alkobote.db") - - viper.SetDefault("Debug", false) - - // Name of the configuration file - viper.SetConfigName("config") - - // Where to find the config file - if configFile == "" { - viper.AddConfigPath("/etc/alkobote.de/") - viper.AddConfigPath(".") - viper.AddConfigPath("$HOME/.config/alkobote.de/") - viper.AddConfigPath("$HOME/alkobote.de/") - } else { - viper.AddConfigPath(configFile) - } - - // Env variables need to be prefixed with "ALKOBOTE_" - viper.SetEnvPrefix("ALKOBOTE") - - // Parses automatic the matching env variables - viper.AutomaticEnv() - - // Reads the config - err := viper.ReadInConfig() - if err != nil { - log.WithFields( - log.Fields{ - "error": err.Error(), - }, - ).Fatal("Fatal error config file") - } - - c.setsConfig() -} - -// Actually sets the config struct -func (c *Config) setsConfig() { - c.DBDriver = viper.GetString("DBDriver") - c.DBHost = viper.GetString("DBHost") - c.DBPort = viper.GetString("DBPort") - c.DBUser = viper.GetString("DBUser") - c.DBPassword = viper.GetString("DBPassword") - c.DBDBName = viper.GetString("DBDBName") - c.DBOptions = viper.GetString("DBOptions") - c.DBPath = viper.GetString("DBPath") - c.Debug = viper.GetBool("Debug") -} |
