-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
70 lines (60 loc) · 1.38 KB
/
Copy pathconfig.go
File metadata and controls
70 lines (60 loc) · 1.38 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"time"
"github.com/spf13/viper"
"go.uber.org/zap"
)
type (
Config struct {
Db Db `json:"db" yaml:"db"`
Tag []string `json:"tag" yaml:"tag"`
TypeMap map[string]GoType `json:"typeMap" yaml:"typeMap"`
Case Case `json:"case" yaml:"case"`
Path Path `json:"path" yaml:"path"`
}
// Db 数据库信息
Db struct {
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
Host string `json:"host" yaml:"host"`
}
Case struct {
Old CaseType `json:"old" yaml:"old"`
New CaseType `json:"new" yaml:"new"`
}
Path struct {
Template string `json:"template" yaml:"template"`
}
)
var (
cfg = new(Config)
)
var (
defaultTimezone = "Asia/Shanghai"
)
func InitConfig() {
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$GOPATH/bin")
if err := viper.ReadInConfig(); err != nil {
log.Error("read config error", zap.Error(err))
return
}
if err := viper.Unmarshal(cfg); err != nil {
log.Error("viper unmarshal error", zap.Error(err))
return
}
if len(cfg.TypeMap) == 0 {
cfg.TypeMap = GoTypeMap
}
}
// 初始化时区
func initTimezone() error {
var err error
time.Local, err = time.LoadLocation(defaultTimezone)
if err != nil {
log.Error("load timezone error", zap.Error(err))
return err
}
return nil
}