-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (34 loc) · 945 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package config
import (
"github.com/spf13/viper"
)
type Config struct {
DBDriver string `mapstructure:"DB_DRIVER"`
DBSource string `mapstructure:"DB_SOURCE"`
ServerAddress string `mapstructure:"SERVER_ADDRESS"`
TokenExpirationMinutes int `mapstructure:"TOKEN_EXPIRATION_MINUTES"`
JWT_SECRET string `mapstructure:"JWT_SECRET"`
TimeZone string `mapstructure:"TIME_ZONE"`
}
func LoadConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("config")
viper.SetConfigType("env")
err = viper.ReadInConfig()
if err != nil {
return
}
err = viper.Unmarshal(&config)
return
}
func LoadTestConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("config_test")
viper.SetConfigType("env")
err = viper.ReadInConfig()
if err != nil {
return
}
err = viper.Unmarshal(&config)
return
}