-
Notifications
You must be signed in to change notification settings - Fork 47
/
conf.go
58 lines (50 loc) · 1.37 KB
/
conf.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
57
58
package utils
import (
"fmt"
"os"
toml "github.com/pelletier/go-toml"
)
var (
// for app config
APP_Address string
// for db config
DB_Driver, DB_Connect string
// for auth config
Auth_Username, Auth_Password, Auth_Secret string
)
func InitConf(confPath string) {
//Check config file
if _, err := os.Stat(confPath); !os.IsNotExist(err) {
if config, err := toml.LoadFile(confPath); err == nil {
APP_Address = config.Get("app.address").(string)
DB_Driver = config.Get("db.driver").(string)
DB_Connect = config.Get("db.connect").(string)
Auth_Username = config.Get("auth.username").(string)
Auth_Password = config.Get("auth.password").(string)
Auth_Secret = config.Get("auth.secret").(string)
}
}
if driver := os.Getenv("DB_DRIVER"); driver != "" {
DB_Driver = driver
}
if connect := os.Getenv("DB_CONNECT"); connect != "" {
DB_Connect = connect
}
if username := os.Getenv("AUTH_USERNAME"); username != "" {
Auth_Username = username
}
if password := os.Getenv("AUTH_PASSWORD"); password != "" {
Auth_Password = password
}
if secret := os.Getenv("Auth_SECRET"); secret != "" {
Auth_Secret = secret
}
fmt.Println("config: ", map[string]interface{}{
"address": APP_Address,
"db_driver": DB_Driver,
"db_connect": DB_Connect,
"auth_username": Auth_Username,
"auth_password": Auth_Password,
"auth_secret": Auth_Secret,
})
}