2016-06-27 09:02:10 +02:00
|
|
|
var (
|
|
|
|
testCfg *Config
|
|
|
|
dbConn *sql.DB
|
|
|
|
)
|
2016-06-27 06:53:23 +02:00
|
|
|
|
|
|
|
func InitViper() error {
|
|
|
|
var err error
|
|
|
|
testCfg = &Config{}
|
|
|
|
|
|
|
|
viper.SetConfigName("sqlboiler")
|
|
|
|
|
|
|
|
configHome := os.Getenv("XDG_CONFIG_HOME")
|
|
|
|
homePath := os.Getenv("HOME")
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
wd = "../"
|
|
|
|
} else {
|
2016-08-06 07:14:28 +02:00
|
|
|
wd = wd + "/.."
|
|
|
|
}
|
2016-06-27 10:34:03 +02:00
|
|
|
|
2016-06-27 06:53:23 +02:00
|
|
|
configPaths := []string{wd}
|
|
|
|
if len(configHome) > 0 {
|
|
|
|
configPaths = append(configPaths, filepath.Join(configHome, "sqlboiler"))
|
|
|
|
} else {
|
|
|
|
configPaths = append(configPaths, filepath.Join(homePath, ".config/sqlboiler"))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range configPaths {
|
|
|
|
viper.AddConfigPath(p)
|
|
|
|
}
|
|
|
|
|
2016-08-06 07:14:28 +02:00
|
|
|
// Ignore errors here, fall back to defaults and validation to provide errs
|
|
|
|
_ = viper.ReadInConfig()
|
|
|
|
viper.AutomaticEnv()
|
2016-06-27 06:53:23 +02:00
|
|
|
|
2016-08-06 07:14:28 +02:00
|
|
|
return nil
|
2016-06-27 06:53:23 +02:00
|
|
|
}
|