summaryrefslogtreecommitdiff
path: root/crawler/config.go
diff options
context:
space:
mode:
authorhorus2018-02-20 17:15:58 +0100
committerhorus2018-02-20 17:15:58 +0100
commitff9790d2e5c3482ccd6109adac475a9868fc0ab6 (patch)
tree3bc0d0727eaeb45b09199b6a711b5d13b3041ade /crawler/config.go
parent4d3d10f634e872d0d4f27311c53f66680e574ad3 (diff)
downloadalkobote-ff9790d2e5c3482ccd6109adac475a9868fc0ab6.tar.gz
Refactoring + adds a more granular log level setting. (crawler)
Diffstat (limited to 'crawler/config.go')
-rw-r--r--crawler/config.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/crawler/config.go b/crawler/config.go
index 27aaa45..f342e30 100644
--- a/crawler/config.go
+++ b/crawler/config.go
@@ -1,6 +1,9 @@
package main
import (
+ "os"
+
+ log "github.com/Sirupsen/logrus"
"github.com/spf13/viper"
)
@@ -18,7 +21,6 @@ type Config struct {
Polr_URL string
Polr_API_Key string
- Debug bool
FixDatabase bool
ShopIDs []string
}
@@ -33,7 +35,6 @@ func (c *Config) parseConfig(configFile string) {
viper.SetDefault("DB_Path", "./alkobote.db")
- viper.SetDefault("Debug", false)
viper.SetDefault("FixDatabase", false)
viper.SetDefault("DisableURLShorter", false)
viper.SetDefault("ShopIDs", []string{})
@@ -48,7 +49,14 @@ func (c *Config) parseConfig(configFile string) {
viper.AddConfigPath("$HOME/.config/alkobote.de/")
viper.AddConfigPath("$HOME/alkobote.de/")
} else {
- viper.AddConfigPath(configFile)
+ stat, err := os.Stat(configFile)
+ if stat.IsDir() || os.IsNotExist(err) {
+ // provided config file does not exist, so we add the path instead
+ viper.AddConfigPath(configFile)
+ } else {
+ // directly sets the config file
+ viper.SetConfigFile(configFile)
+ }
}
// Env variables need to be prefixed with "ALKOBOTE_"
@@ -62,6 +70,7 @@ func (c *Config) parseConfig(configFile string) {
if err != nil {
Fatal(err, "Config: Error parsing config file.")
}
+ log.Debug("Config: Config file used: " + viper.ConfigFileUsed())
c.setsConfig()
}
@@ -76,7 +85,6 @@ func (c *Config) setsConfig() {
c.DBDBName = viper.GetString("DB_DBName")
c.DBOptions = viper.GetString("DB_Options")
c.DBPath = viper.GetString("DB_Path")
- c.Debug = viper.GetBool("Debug")
c.FixDatabase = viper.GetBool("FixDatabase")
c.DisableURLShorter = viper.GetBool("DisableURLShorter")
c.ShopIDs = viper.GetStringSlice("ShopIDs")