forked from xiaojiaoyu100/aliyun-acm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_config.go
45 lines (42 loc) · 932 Bytes
/
get_config.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
package aliacm
import (
"errors"
"net/http"
)
// GetConfigRequest 获取配置参数
type GetConfigRequest struct {
Tenant string `url:"tenant"`
DataID string `url:"dataId"`
Group string `url:"group"`
}
// GetConfig 获取配置
func (d *Diamond) GetConfig(args *GetConfigRequest) ([]byte, error) {
if len(args.Group) == 0 {
args.Group = DefaultGroup
}
if len(args.Tenant) == 0 {
args.Tenant = d.option.tenant
}
ip, err := d.QueryIP()
if err != nil {
return nil, err
}
header := make(http.Header)
if err := d.withUsual(args.Tenant, args.Group)(header); err != nil {
return nil, err
}
request := d.c.NewRequest().
WithTimeout(apiTimeout).
WithPath(acmConfig.String(ip)).
WithQueryParam(args).
WithHeader(header).
Get()
response, err := d.c.Do(request)
if err != nil {
return nil, err
}
if !response.Success() {
return nil, errors.New(response.String())
}
return response.Body(), nil
}