-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.go
55 lines (45 loc) · 1.04 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
package rocketmq5Kit
import (
"github.com/apache/rocketmq-clients/golang/v5/credentials"
"github.com/richelieu-yang/chimera/v2/src/core/errorKit"
"github.com/richelieu-yang/chimera/v2/src/core/sliceKit"
"github.com/richelieu-yang/chimera/v2/src/log/logrusKit"
"github.com/sirupsen/logrus"
)
var config *Config
func MustSetUp(config *Config) {
if err := SetUp(config); err != nil {
logrusKit.DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
func SetUp(c *Config) error {
if err := check(c); err != nil {
return err
}
if err := initClientLog(c.ClientLogPath); err != nil {
return err
}
config = c
return nil
}
func check(c *Config) error {
if c == nil {
return errorKit.New("c == nil")
}
// Endpoints
s := sliceKit.RemoveEmpty(c.Endpoints, true)
if err := sliceKit.AssertNotEmpty(s, "c.Endpoints"); err != nil {
return err
}
c.Endpoints = s
// Credentials
if c.Credentials == nil {
c.Credentials = &credentials.SessionCredentials{
AccessKey: "",
AccessSecret: "",
SecurityToken: "",
}
}
return nil
}