diff --git a/.gitignore b/.gitignore index 72628a5..a5ee99e 100644 --- a/.gitignore +++ b/.gitignore @@ -169,3 +169,6 @@ Network Trash Folder Temporary Items .apdisk +# Application +config.dev.yaml + diff --git a/config/config.go b/config/config.go index 9a83301..357cea1 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,11 @@ package config -import "github.com/spf13/viper" +import ( + "fmt" + "github.com/spf13/viper" + "log" + "os" +) type Config struct { Server ServerConfig `mapstructure:"server"` @@ -14,7 +19,17 @@ type ServerConfig struct { var AppConfig Config func LoadConfig() error { - viper.SetConfigName("config") + env := os.Getenv("PROFILE") + var configName string + if env == "" { + configName = "config" + } else { + configName = fmt.Sprint("config.", env) + } + + log.Println("Loading config: ", configName) + + viper.SetConfigName(configName) viper.SetConfigType("yaml") viper.AddConfigPath(".")