/
config.go
46 lines (40 loc) · 906 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
41
42
43
44
45
46
package agscheduler
import (
"github.com/sirupsen/logrus"
"github.com/timest/env"
"time"
)
var Config AGSConfig
type AGSConfig struct {
Log LogConfig
PG PGConfig
}
type LogConfig struct {
Level string `default:"info"`
Json bool `default:"false"`
}
type PGConfig struct {
Addr string `default:"localhost:5432"`
User string `default:"postgres"`
Password string `default:"postgres"`
Database string `default:"postgres"`
PoolSize int `default:"3"`
}
func init() {
config := AGSConfig{}
env.IgnorePrefix()
err := env.Fill(&config)
if err != nil {
AGSLog.WithFields(GenASGModule("config")).
WithError(err).
Warningln("init env failure.")
}
Config = config
logLevel, err := logrus.ParseLevel(Config.Log.Level)
if err == nil {
AGSLog.SetLevel(logLevel)
}
if Config.Log.Json {
AGSLog.SetFormatter(&logrus.JSONFormatter{TimestampFormat: time.RFC3339Nano})
}
}