-
Notifications
You must be signed in to change notification settings - Fork 701
/
register.go
48 lines (44 loc) · 1.43 KB
/
register.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 apollo
import (
"net/url"
"github.com/douyu/jupiter/pkg/conf"
"github.com/douyu/jupiter/pkg/flag"
"github.com/douyu/jupiter/pkg/xlog"
"github.com/philchia/agollo/v4"
)
// DataSourceApollo defines apollo scheme
const DataSourceApollo = "apollo"
func init() {
conf.Register(DataSourceApollo, func() conf.DataSource {
var (
configAddr = flag.String("config")
)
if configAddr == "" {
xlog.Panic("new apollo dataSource, configAddr is empty")
return nil
}
// configAddr is a string in this format:
// apollo://ip:port?appId=XXX&cluster=XXX&namespaceName=XXX&key=XXX&accesskeySecret=XXX&insecureSkipVerify=XXX&cacheDir=XXX
urlObj, err := url.Parse(configAddr)
if err != nil {
xlog.Panic("parse configAddr error", xlog.FieldErr(err))
return nil
}
apolloConf := agollo.Conf{
AppID: urlObj.Query().Get("appId"),
Cluster: urlObj.Query().Get("cluster"),
NameSpaceNames: []string{urlObj.Query().Get("namespaceName")},
MetaAddr: urlObj.Host,
InsecureSkipVerify: true,
AccesskeySecret: urlObj.Query().Get("accesskeySecret"),
CacheDir: ".",
}
if urlObj.Query().Get("insecureSkipVerify") == "false" {
apolloConf.InsecureSkipVerify = false
}
if urlObj.Query().Get("cacheDir") != "" {
apolloConf.CacheDir = urlObj.Query().Get("cacheDir")
}
return NewDataSource(&apolloConf, urlObj.Query().Get("namespaceName"), urlObj.Query().Get("key"))
})
}