ac549c9207
- Stop failing on config file load, use the validation in the test config stuff.
37 lines
731 B
Smarty
37 lines
731 B
Smarty
var (
|
|
testCfg *Config
|
|
dbConn *sql.DB
|
|
)
|
|
|
|
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 {
|
|
wd = wd + "/.."
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
// Ignore errors here, fall back to defaults and validation to provide errs
|
|
_ = viper.ReadInConfig()
|
|
viper.AutomaticEnv()
|
|
|
|
return nil
|
|
}
|