主要接口
所有文档
menu

标签管理 TAG

主要接口

主要接口

标签管理(TAG)API对于每个HTTP请求,认证签名放在Authorization头域中,后端统一认证。且后端在Response头域中会添加x-bce-request-id,作为请求唯一标识,方便追踪定位问题。

目前支持的标签管理(TAG)API接口如下:

  • 创建标签
  • 删除标签
  • 标签列表
  • 查看标签下绑定的资源
  • 标签列表
  • 批量绑定资源
  • 批量解绑资源
  • 删除标签关联关系
  • 全量更新资源的绑定关系

创建标签

使用以下代码可以创建标签

args := &TagsRequest{
    Tags: []Tag{
    {
        TagKey:   "key",
        TagValue: "val",
    }, {
        TagKey:   "key",
        TagValue: "val1",
    },
    },
}

result, err := client.CreateTags(args)
if err != nil {
    fmt.Println("CreateTags failed:", err)
} else {
    fmt.Println("CreateTags success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

删除标签

使用以下代码可以删除标签

args := &TagsRequest{
    Tags: []Tag{
    {
        TagKey:   "key",
        TagValue: "val",
    }, {
        TagKey:   "key",
        TagValue: "val1",
    },
    },
}

result, err := client.DeleteTags(args)
if err != nil {
    fmt.Println("DeleteTags failed:", err)
} else {
    fmt.Println("DeleteTags success: ")
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

查看标签下绑定的资源

使用以下代码可以查看标签下绑定的资源

tagKey := "key"
tagValue := "val"
region := "bj"
resourceType := "BCC"

res, err := tagClient.TagsResources(tagKey, tagValue, region, resourceType)
if err != nil {
    fmt.Println("TagsResources failed:", err)
} else {
    fmt.Println("TagsResources success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

标签列表

使用以下代码可以标签列表

tagKey := "go_sdk_key"
tagValue := "go_sdk_val"
res, err := tagClient.UserTagList(tagKey, tagValue)
if err != nil {
    fmt.Println("UserTagList failed:", err)
} else {
    fmt.Println("UserTagList success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

批量绑定资源

使用以下代码可以批量绑定资源

args := &CreateAssociationsByTagRequest{
    TagKey:      "key",
    TagValue:    "val",
    ServiceType: "BCC",
    Resource: []Resource{
        {
            ResourceId:  "58426",
            ServiceType: "BCC",
            Region:      "bj",
        },
        {
            ResourceId:  "58428",
            ServiceType: "BCC",
            Region:      "bj",
        },
    },
}
err := tagClient.CreateAssociationsByTag(args)
if err != nil {
    fmt.Println("CreateAssociationsByTag failed:", err)
} else {
    fmt.Println("CreateAssociationsByTag success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

批量解绑资源

使用以下代码可以批量解绑资源

args := &DeleteAssociationsByTagRequest{
    TagKey:      "key",
    TagValue:    "val",
    ServiceType: "BCC",
    Resource: []Resource{
        {
            ResourceId:  "58426",
            ServiceType: "BCC",
            Region:      "bj",
        },
        {
            ResourceId:  "58428",
            ServiceType: "BCC",
            Region:      "bj",
        },
    },
}
err := tagClient.DeleteAssociationsByTag(args)
if err != nil {
    fmt.Println("DeleteAssociationsByTag failed:", err)
} else {
    fmt.Println("DeleteAssociationsByTag success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

删除标签关联关系

使用以下代码可以删除标签关联关系

args := &DeleteTagAssociationRequest{
    Resource: &Resource{
        {
            ResourceId:  "58426",
            ServiceType: "BCC",
            Region:      "bj",
        },
        {
            ResourceId:  "58428",
            ServiceType: "BCC",
            Region:      "bj",
        },
    },
}
err := tagClient.DeleteTagAssociation(args)
if err != nil {
    fmt.Println("DeleteTagAssociation failed:", err)
} else {
    fmt.Println("DeleteTagAssociation success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

查询用户的标签信息列表

使用以下代码可以查询用户的标签信息列表

var strongAssociation = true
args := &FullTagListRequest{
    TagKey:   "key",
    TagValue: "val",
    Regions: []string{
        "bj",
    },
    ServiceTypes: []string{
        "BCC",
    },
    ResourceIds:   []string{
		"58426",
    },
}
err := tagClient.QueryFullList(args)
if err != nil {
    fmt.Println("QueryFullList failed:", err)
} else {
    fmt.Println("QueryFullList success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档

全量更新资源的绑定关系

使用以下代码可以全量更新资源的绑定关系

args := &CreateAssociationsByTagRequest{
    TagKey:      "key",
    TagValue:    "val",
    ServiceType: "BCC",
    Resource: []Resource{
        {
            ResourceId:  "58426",
            ServiceType: "BCC",
            Region:      "bj",
        },
        {
            ResourceId:  "58428",
            ServiceType: "BCC",
            Region:      "bj",
        },
    },
}
err := tagClient.CreateAssociationsByTag(args)
if err != nil {
    fmt.Println("CreateAssociationsByTag failed:", err)
} else {
    fmt.Println("CreateAssociationsByTag success: ", result)
}

提示:

  1. 接口详细描述请参考标签管理(TAG)API文档
上一篇
初始化
下一篇
错误处理