-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.go
61 lines (51 loc) · 1.28 KB
/
setup.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
package rocketmq5Kit
import (
"github.com/apache/rocketmq-clients/golang/v5/credentials"
"github.com/richelieu-yang/chimera/v3/src/core/errorKit"
"github.com/richelieu-yang/chimera/v3/src/log/logrusKit"
"github.com/richelieu-yang/chimera/v3/src/validateKit"
"github.com/sirupsen/logrus"
)
var (
NotSetupError = errorKit.Newf("haven’t been set up correctly")
)
var config *Config
func MustSetUp(c *Config, clientLogPath string, verifyConfig *VerifyConfig) {
if err := SetUp(c, clientLogPath, verifyConfig); err != nil {
logrusKit.DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
// SetUp
/*
@param clientLogPath 可以为""(输出到控制台)
@param verifyConfig 可以为nil(不进行验证)
*/
func SetUp(c *Config, clientLogPath string, verifyConfig *VerifyConfig) (err error) {
defer func() {
if err != nil {
config = nil
}
}()
if err = validateKit.Struct(c); err != nil {
return
}
// Richelieu: 防止客户端库源码内部panic
if c.Credentials == nil {
c.Credentials = &credentials.SessionCredentials{
AccessKey: "",
AccessSecret: "",
SecurityToken: "",
}
}
// 客户端日志输出
if err = setClientLog(clientLogPath); err != nil {
return
}
config = c
// verify
if err = verify(verifyConfig); err != nil {
return
}
return
}