本文介绍如何添加静态路由。
// Example Code generated by Beijing Volcanoengine Technology. package directconnectemample import ( "fmt" "github.com/volcengine/volcengine-go-sdk/service/directconnect" "github.com/volcengine/volcengine-go-sdk/volcengine" "github.com/volcengine/volcengine-go-sdk/volcengine/credentials" "github.com/volcengine/volcengine-go-sdk/volcengine/session" ) func CreateDirectConnectGatewayRoute() { // 设置您的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 := directconnect.New(sess) // 添加路由信息。 createDirectConnectGatewayRouteInput := &directconnect.CreateDirectConnectGatewayRouteInput{ DestinationCidrBlock: volcengine.String("172.XX.XX.0/24"), // 设置专线网关路由的目的网段。 DirectConnectGatewayId: volcengine.String("dcg-2fe3zsmkshs59g****"), // 设置待添加静态路由的专线网关的ID。 NextHopId: volcengine.String("dcv-7qthudw0ll6jmc****"), // 设置专线网关路由下一跳虚拟接口的ID。 } // 发起请求并处理返回或异常。 resp, err := svc.CreateDirectConnectGatewayRoute(createDirectConnectGatewayRouteInput) if err != nil { panic(err) } fmt.Println(resp) }