2 Star 8 Fork 0

tencentcloud/tencentcloud-sdk-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
describe_security_group_policies.go 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
ZhiQiang Fan 提交于 2019-01-01 21:24 +08:00 . add vpc describe sg policy example
package main
import (
"fmt"
"os"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312"
)
func main() {
credential := common.NewCredential(
os.Getenv("TENCENTCLOUD_SECRET_ID"),
os.Getenv("TENCENTCLOUD_SECRET_KEY"),
)
client, _ := vpc.NewClient(credential, "ap-guangzhou", profile.NewClientProfile())
sgreq := vpc.NewDescribeSecurityGroupsRequest()
sgresp, err := client.DescribeSecurityGroups(sgreq)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if *sgresp.Response.TotalCount < 1 {
fmt.Printf("No security group found.")
return
}
request := vpc.NewDescribeSecurityGroupPoliciesRequest()
// we don't care which one, hence with no filter and just use the first one
request.SecurityGroupId = sgresp.Response.SecurityGroupSet[0].SecurityGroupId
response, err := client.DescribeSecurityGroupPolicies(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}
fmt.Printf("%s", response.ToJsonString())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tencentcloud/tencentcloud-sdk-go.git
git@gitee.com:tencentcloud/tencentcloud-sdk-go.git
tencentcloud
tencentcloud-sdk-go
tencentcloud-sdk-go
v3.0.197

搜索帮助