-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAliyunApi.go
174 lines (163 loc) · 5.54 KB
/
AliyunApi.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// This file is auto-generated, don't edit it. Thanks.
package utils
import (
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
"horizon/config"
)
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *openapi.Client, _err error) {
config := &openapi.Config{
// 必填,您的 AccessKey ID
AccessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
AccessKeySecret: accessKeySecret,
}
// Endpoint 请参考 https://api.aliyun.com/product/mse
config.Endpoint = tea.String("mse.cn-shanghai.aliyuncs.com")
_result = &openapi.Client{}
_result, _err = openapi.NewClient(config)
return _result, _err
}
/**
* API 相关
* @param path params
* @return OpenApi.Params
*/
func CreateApiInfo(action string) (_result *openapi.Params) {
params := &openapi.Params{
// 接口名称
Action: tea.String(action),
// 接口版本
Version: tea.String("2019-05-31"),
// 接口协议
Protocol: tea.String("HTTPS"),
// 接口 HTTP 方法
Method: tea.String("POST"),
AuthType: tea.String("AK"),
Style: tea.String("RPC"),
// 接口 PATH
Pathname: tea.String("/"),
// 接口请求体内容格式
ReqBodyType: tea.String("json"),
// 接口响应体内容格式
BodyType: tea.String("json"),
}
_result = params
return _result
}
func ListClusters(pageNum int, pageSize int, clusterAliasName string) (rs map[string]interface{}, _err error) {
client, _err := CreateClient(tea.String(config.Conf.Aliyun.AccessKeyId), tea.String(config.Conf.Aliyun.AccessKeySecret))
if _err != nil {
return rs, _err
}
action := "ListClusters"
params := CreateApiInfo(action)
// query params
queries := map[string]interface{}{}
queries["RegionId"] = tea.String("cn-shanghai")
queries["PageNum"] = tea.Int(pageNum)
queries["PageSize"] = tea.Int(pageSize)
if clusterAliasName != "" {
queries["ClusterAliasName"] = tea.String(clusterAliasName)
}
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// 复制代码运行请自行打印 API 的返回值
// 返回值为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。
rs, _err = client.CallApi(params, request, runtime)
if _err != nil {
return nil, _err
}
return rs, _err
}
func ListEngineNamespaces(instanceId string) (rs map[string]interface{}, _err error) {
client, _err := CreateClient(tea.String(config.Conf.Aliyun.AccessKeyId), tea.String(config.Conf.Aliyun.AccessKeySecret))
if _err != nil {
return rs, _err
}
action := "ListEngineNamespaces"
params := CreateApiInfo(action)
// query params
queries := map[string]interface{}{}
queries["InstanceId"] = tea.String(instanceId)
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// 复制代码运行请自行打印 API 的返回值
// 返回值为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。
rs, _err = client.CallApi(params, request, runtime)
if _err != nil {
return nil, _err
}
return rs, _err
}
func ListNacosConfigs(pageNum int, pageSize int, instanceId string, namespaceId string, dataId string) (rs map[string]interface{}, _err error) {
client, _err := CreateClient(tea.String(config.Conf.Aliyun.AccessKeyId), tea.String(config.Conf.Aliyun.AccessKeySecret))
if _err != nil {
return rs, _err
}
action := "ListNacosConfigs"
params := CreateApiInfo(action)
// query params
queries := map[string]interface{}{}
queries["RegionId"] = tea.String("cn-shanghai")
queries["PageNum"] = tea.Int(pageNum)
queries["PageSize"] = tea.Int(pageSize)
queries["InstanceId"] = tea.String(instanceId)
queries["NamespaceId"] = tea.String(namespaceId)
if dataId != "" {
queries["DataId"] = tea.String(dataId)
}
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// 复制代码运行请自行打印 API 的返回值
// 返回值为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。
rs, _err = client.CallApi(params, request, runtime)
if _err != nil {
return nil, _err
}
return rs, _err
}
func GetNacosConfig(instanceId string, namespaceId string, dataId string, group string) (rs map[string]interface{}, _err error) {
client, _err := CreateClient(tea.String(config.Conf.Aliyun.AccessKeyId), tea.String(config.Conf.Aliyun.AccessKeySecret))
if _err != nil {
return rs, _err
}
action := "GetNacosConfig"
params := CreateApiInfo(action)
// query params
queries := map[string]interface{}{}
queries["InstanceId"] = tea.String(instanceId)
queries["NamespaceId"] = tea.String(namespaceId)
queries["DataId"] = tea.String(dataId)
queries["Group"] = tea.String(group)
// runtime options
runtime := &util.RuntimeOptions{}
request := &openapi.OpenApiRequest{
Query: openapiutil.Query(queries),
}
// 复制代码运行请自行打印 API 的返回值
// 返回值为 Map 类型,可从 Map 中获得三类数据:响应体 body、响应头 headers、HTTP 返回的状态码 statusCode。
rs, _err = client.CallApi(params, request, runtime)
if _err != nil {
return nil, _err
}
return rs, _err
}