-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.go
48 lines (44 loc) · 818 Bytes
/
app.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
package conf
import (
"github.com/busgo/pink/pkg/log"
"github.com/spf13/viper"
"os"
)
type AppConf struct {
Etcd struct {
Endpoints []string
UserName string
Password string
DialTimeout int64
}
Mysql struct {
DSN string
MaxOpenConns int
MaxIdleConns int
}
Log struct {
FileName string
Level int32
ServiceName string
}
Port int32
}
func NewAppConf(filePath string) (*AppConf, error) {
file, err := os.Open(filePath)
if err != nil {
log.Errorf("can not open file:%s", filePath)
return nil, err
}
v := viper.New()
v.SetConfigType("yaml")
err = v.ReadConfig(file)
if err != nil {
return nil, err
}
c := new(AppConf)
err = v.Unmarshal(c)
if err == nil {
_ = log.NewLoggerSugar(c.Log.ServiceName, c.Log.FileName, c.Log.Level)
}
return c, err
}