generated from antoniopaya22/go-rest-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
56 lines (44 loc) · 992 Bytes
/
configuration.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package config
import (
"log"
"github.com/spf13/viper"
)
var Config *Configuration
type Configuration struct {
Server ServerConfiguration
Database DatabaseConfiguration
}
type DatabaseConfiguration struct {
Driver string
Dbname string
Username string
Password string
Host string
Port string
MaxLifetime int
MaxOpenConns int
MaxIdleConns int
}
type ServerConfiguration struct {
Port string
Secret string
Mode string
}
// SetupDB initialize configuration
func Setup(configPath string) {
var configuration *Configuration
viper.SetConfigFile(configPath)
viper.SetConfigType("yaml")
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("Error reading config file, %s", err)
}
err := viper.Unmarshal(&configuration)
if err != nil {
log.Fatalf("Unable to decode into struct, %v", err)
}
Config = configuration
}
// GetConfig helps you to get configuration data
func GetConfig() *Configuration {
return Config
}