/
conf.go
114 lines (103 loc) · 2.27 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package conf
import (
"github.com/spf13/viper"
)
var (
Conf config // holds the global app config.
)
type config struct {
// 应用配置
App app
Oss oss
Image image
Info info
}
type info struct {
RegexpAccount string
MemberSuperRole int // 超级管理员.
MemberAdminRole int //普通管理员.
MemberGeneralRole int //普通用户.
RegexpEmail string
PageSize int
RollPage int
DefaultAvatar string //获取默认头像
DefaultCover string
BookFounder int
BookAdmin int
BookEditor int
BookObserver int
WorkingDirectory string
TokenSize int // 获取阅读令牌长度
}
type image struct {
Domain string
Path string
}
type app struct {
Name string `toml:"name"`
Wechat wechat `toml:"wechat"`
WechatPay wechatPay
WechatOpen wechatOpen
CdnName string
File string `toml:"file"`
DbPrefix string `toml:"dbPrefix"`
AppKey string `toml:"appKey"`
Baidumapkey string
ExportHeader string
ExportFooter string
ExportFontSize string
ExportPagerSize string
ExportCreator string
ExportMarginLeft string
ExportMarginRight string
ExportMarginTop string
ExportMarginBottom string
}
type wechat struct {
CodeToSessURL string
AppID string
AppSecret string
}
type wechatPay struct {
AppID string
MchID string
Key string
CallbackApi string
}
type wechatOpen struct {
AppID string
AppSecret string
RedirectURI string
Scope string
}
type oss struct {
Domain string
}
func Init() error {
// Set defaults.
Conf = config{
Info: info{
RegexpAccount: `^[a-zA-Z][a-zA-z0-9\.]{2,50}$`,
MemberSuperRole: 0,
MemberAdminRole: 1,
MemberGeneralRole: 2,
RegexpEmail: `^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$`,
PageSize: 20,
RollPage: 4,
DefaultAvatar: "/static/images/headimgurl.jpg",
DefaultCover: "/static/images/book.jpg",
// 创始人.
BookFounder: 0,
//管理者
BookAdmin: 1,
//编辑者.
BookEditor: 2,
//观察者
BookObserver: 3,
WorkingDirectory: "./",
TokenSize: 12,
},
}
err := viper.Unmarshal(&Conf)
return err
}