主要接口
更新时间:2024-04-29
主要接口
标签管理(TAG)API对于每个HTTP请求,认证签名放在Authorization头域中,后端统一认证。且后端在Response头域中会添加x-bce-request-id,作为请求唯一标识,方便追踪定位问题。
目前支持的标签管理(TAG)API接口如下:
- 创建标签
- 删除标签
- 标签列表
- 查看标签下绑定的资源
- 标签列表
- 批量绑定资源
- 批量解绑资源
- 删除标签关联关系
- 全量更新资源的绑定关系
创建标签
使用以下代码可以创建标签
Go
1args := &TagsRequest{
2 Tags: []Tag{
3 {
4 TagKey: "key",
5 TagValue: "val",
6 }, {
7 TagKey: "key",
8 TagValue: "val1",
9 },
10 },
11}
12
13result, err := client.CreateTags(args)
14if err != nil {
15 fmt.Println("CreateTags failed:", err)
16} else {
17 fmt.Println("CreateTags success: ", result)
18}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
删除标签
使用以下代码可以删除标签
Go
1args := &TagsRequest{
2 Tags: []Tag{
3 {
4 TagKey: "key",
5 TagValue: "val",
6 }, {
7 TagKey: "key",
8 TagValue: "val1",
9 },
10 },
11}
12
13result, err := client.DeleteTags(args)
14if err != nil {
15 fmt.Println("DeleteTags failed:", err)
16} else {
17 fmt.Println("DeleteTags success: ")
18}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
查看标签下绑定的资源
使用以下代码可以查看标签下绑定的资源
Go
1tagKey := "key"
2tagValue := "val"
3region := "bj"
4resourceType := "BCC"
5
6res, err := tagClient.TagsResources(tagKey, tagValue, region, resourceType)
7if err != nil {
8 fmt.Println("TagsResources failed:", err)
9} else {
10 fmt.Println("TagsResources success: ", result)
11}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
标签列表
使用以下代码可以标签列表
Go
1tagKey := "go_sdk_key"
2tagValue := "go_sdk_val"
3res, err := tagClient.UserTagList(tagKey, tagValue)
4if err != nil {
5 fmt.Println("UserTagList failed:", err)
6} else {
7 fmt.Println("UserTagList success: ", result)
8}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
批量绑定资源
使用以下代码可以批量绑定资源
Go
1args := &CreateAssociationsByTagRequest{
2 TagKey: "key",
3 TagValue: "val",
4 ServiceType: "BCC",
5 Resource: []Resource{
6 {
7 ResourceId: "58426",
8 ServiceType: "BCC",
9 Region: "bj",
10 },
11 {
12 ResourceId: "58428",
13 ServiceType: "BCC",
14 Region: "bj",
15 },
16 },
17}
18err := tagClient.CreateAssociationsByTag(args)
19if err != nil {
20 fmt.Println("CreateAssociationsByTag failed:", err)
21} else {
22 fmt.Println("CreateAssociationsByTag success: ", result)
23}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
批量解绑资源
使用以下代码可以批量解绑资源
Go
1args := &DeleteAssociationsByTagRequest{
2 TagKey: "key",
3 TagValue: "val",
4 ServiceType: "BCC",
5 Resource: []Resource{
6 {
7 ResourceId: "58426",
8 ServiceType: "BCC",
9 Region: "bj",
10 },
11 {
12 ResourceId: "58428",
13 ServiceType: "BCC",
14 Region: "bj",
15 },
16 },
17}
18err := tagClient.DeleteAssociationsByTag(args)
19if err != nil {
20 fmt.Println("DeleteAssociationsByTag failed:", err)
21} else {
22 fmt.Println("DeleteAssociationsByTag success: ", result)
23}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
删除标签关联关系
使用以下代码可以删除标签关联关系
Go
1args := &DeleteTagAssociationRequest{
2 Resource: &Resource{
3 {
4 ResourceId: "58426",
5 ServiceType: "BCC",
6 Region: "bj",
7 },
8 {
9 ResourceId: "58428",
10 ServiceType: "BCC",
11 Region: "bj",
12 },
13 },
14}
15err := tagClient.DeleteTagAssociation(args)
16if err != nil {
17 fmt.Println("DeleteTagAssociation failed:", err)
18} else {
19 fmt.Println("DeleteTagAssociation success: ", result)
20}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
查询用户的标签信息列表
使用以下代码可以查询用户的标签信息列表
Go
1var strongAssociation = true
2args := &FullTagListRequest{
3 TagKey: "key",
4 TagValue: "val",
5 Regions: []string{
6 "bj",
7 },
8 ServiceTypes: []string{
9 "BCC",
10 },
11 ResourceIds: []string{
12 "58426",
13 },
14}
15err := tagClient.QueryFullList(args)
16if err != nil {
17 fmt.Println("QueryFullList failed:", err)
18} else {
19 fmt.Println("QueryFullList success: ", result)
20}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。
全量更新资源的绑定关系
使用以下代码可以全量更新资源的绑定关系
Go
1args := &CreateAssociationsByTagRequest{
2 TagKey: "key",
3 TagValue: "val",
4 ServiceType: "BCC",
5 Resource: []Resource{
6 {
7 ResourceId: "58426",
8 ServiceType: "BCC",
9 Region: "bj",
10 },
11 {
12 ResourceId: "58428",
13 ServiceType: "BCC",
14 Region: "bj",
15 },
16 },
17}
18err := tagClient.CreateAssociationsByTag(args)
19if err != nil {
20 fmt.Println("CreateAssociationsByTag failed:", err)
21} else {
22 fmt.Println("CreateAssociationsByTag success: ", result)
23}
提示:
- 接口详细描述请参考标签管理(TAG)API文档。