You need to enable JavaScript to run this app.
导航

查询子网

最近更新时间2023.08.29 19:07:40

首次发布时间2023.06.09 11:20:34

本文介绍如何按条件查询子网。

示例代码

// Example Code generated by Beijing Volcanoengine Technology.

package vpcexample

import (
	"fmt"

	"github.com/volcengine/volcengine-go-sdk/service/vpc"
	"github.com/volcengine/volcengine-go-sdk/volcengine"
	"github.com/volcengine/volcengine-go-sdk/volcengine/credentials"
	"github.com/volcengine/volcengine-go-sdk/volcengine/session"
)

func DescribeSubnets() {
  // 设置您的ak、sk、要访问的地域
	ak, sk, region := "Your AK", "Your SK", "Region"
	config := volcengine.NewConfig().
		WithRegion(region).
		WithCredentials(credentials.NewStaticCredentials(ak, sk, ""))
	sess, err := session.NewSession(config)
	if err != nil {
		panic(err)
	}
	svc := vpc.New(sess)

	// 按条件查询子网
	describeSubnetsInput := &vpc.DescribeSubnetsInput{
		ZoneId: volcengine.String("cn-beijing-a"), // 可用区的ID
	}

  // 发起请求并处理返回或异常
	resp, err := svc.DescribeSubnets(describeSubnetsInput)
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}

相关文档