26 lines
486 B
Go
26 lines
486 B
Go
package util
|
|
|
|
import "github.com/spf13/viper"
|
|
|
|
type Config struct {
|
|
DBDriver string `mapstructure:"DB_TYPE"`
|
|
DBSource string `mapstructure:"DB_SOURCE"`
|
|
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
|
|
}
|
|
|
|
func LoadConfig(path string) (config Config, err error) {
|
|
viper.AddConfigPath(path)
|
|
viper.SetConfigName("dev")
|
|
viper.SetConfigType("env")
|
|
|
|
viper.AutomaticEnv()
|
|
|
|
err = viper.ReadInConfig()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = viper.Unmarshal(&config)
|
|
return
|
|
}
|