|
@@ -26,6 +26,7 @@ func getEnv() string {
|
|
|
|
|
|
// Config : application config stored as global variable
|
|
// Config : application config stored as global variable
|
|
var Config *EnvironmentConfig
|
|
var Config *EnvironmentConfig
|
|
|
|
+var SetupErr error
|
|
|
|
|
|
// EnvironmentConfig - environment conf struct
|
|
// EnvironmentConfig - environment conf struct
|
|
type EnvironmentConfig struct {
|
|
type EnvironmentConfig struct {
|
|
@@ -90,25 +91,26 @@ type SQLConfig struct {
|
|
}
|
|
}
|
|
|
|
|
|
// reading in the env file
|
|
// reading in the env file
|
|
-func readConfig() *EnvironmentConfig {
|
|
|
|
- file := fmt.Sprintf("config/environments/%s.yaml", getEnv())
|
|
|
|
|
|
+func readConfig() (*EnvironmentConfig, error) {
|
|
|
|
+ file := fmt.Sprintf("environments/%s.yaml", getEnv())
|
|
f, err := os.Open(file)
|
|
f, err := os.Open(file)
|
|
var cfg EnvironmentConfig
|
|
var cfg EnvironmentConfig
|
|
if err != nil {
|
|
if err != nil {
|
|
- return &cfg
|
|
|
|
|
|
+ return &cfg, err
|
|
}
|
|
}
|
|
defer f.Close()
|
|
defer f.Close()
|
|
|
|
|
|
decoder := yaml.NewDecoder(f)
|
|
decoder := yaml.NewDecoder(f)
|
|
- err = decoder.Decode(&cfg)
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(err)
|
|
|
|
- os.Exit(2)
|
|
|
|
|
|
+ if decoder.Decode(&cfg) != nil {
|
|
|
|
+ return &cfg, err
|
|
}
|
|
}
|
|
- return &cfg
|
|
|
|
|
|
+ return &cfg, err
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
- Config = readConfig()
|
|
|
|
|
|
+ if Config, SetupErr = readConfig(); SetupErr != nil {
|
|
|
|
+ log.Fatal(SetupErr)
|
|
|
|
+ os.Exit(2)
|
|
|
|
+ }
|
|
}
|
|
}
|