-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconfig.go
47 lines (42 loc) · 1 KB
/
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
41
42
43
44
45
46
47
package main
import (
"github.com/jinzhu/configor"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
)
var config = struct {
APP struct {
Debug bool `default:"false"`
Host string `default:"0.0.0.0"`
Port string `default:"1324"`
PageSize int `default:"10"`
BaseURL string `default:"https://api.example.com/"`
FileURL string `default:"https://static.example.com/"`
}
DB struct {
Host string `default:"mysql"`
Port string `default:"3306"`
User string `default:"root"`
Password string `default:"root"`
Name string `default:"art"`
}
Redis struct {
Host string `default:"redis"`
Port string `default:"6379"`
Password string
DB int `default:"0"`
}
}{}
func init() {
godotenv.Load()
configor.Load(&config)
if config.APP.Debug {
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "06-01-02 15:04:05.00",
})
logrus.SetLevel(logrus.DebugLevel)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
}