Created
April 15, 2022 08:41
-
-
Save Develp10/238ee5ad71d6f2a44b7095568df438db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package config | |
| import ( | |
| "github.com/spf13/viper" | |
| ) | |
| type Config struct { | |
| Port string `mapstructure:"PORT"` | |
| DBHost string `mapstructure:"DB_HOST"` | |
| DBUser string `mapstructure:"DB_USER"` | |
| DBPass string `mapstructure:"DB_PASS"` | |
| DBName string `mapstructure:"DB_NAME"` | |
| DBPort string `mapstructure:"DB_PORT"` | |
| } | |
| func LoadConfig() (c Config, err error) { | |
| viper.AddConfigPath("./") | |
| viper.SetConfigName(".env") | |
| viper.SetConfigType("env") | |
| viper.AutomaticEnv() | |
| err = viper.ReadInConfig() | |
| if err != nil { | |
| return | |
| } | |
| err = viper.Unmarshal(&c) | |
| return | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment