All Products
Search
Document Center

:Query Endpoint information (Go SDK V1)

Last Updated:Nov 28, 2025

This topic describes how to query Endpoint information for all supported regions or a specific region. This includes public (IPv4) Endpoints, internal Endpoints (classic network or VPC), and acceleration endpoints for global uploads and downloads.

Notes

  • You can query Endpoint information using Go SDK V2.2.8 and later.

  • The ability to query Endpoint information for a region depends on whether OSS supports that region, not on whether you have created a bucket in that region.

  • In this topic, the public endpoint of the China (Hangzhou) region is used. If you want to access OSS from other Alibaba Cloud services in the same region as OSS, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.

  • In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.

  • In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Configure OSSClient instances.

Query Endpoint information for all supported regions

The following code shows how to query Endpoint information for all supported regions.

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Create an OSSClient instance.
	// Set yourEndpoint to the Endpoint of the bucket. For example, for the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual Endpoint.
	// Set yourRegion to the region where the bucket is located. For example, for the China (Hangzhou) region, set the region to cn-hangzhou. For other regions, specify the actual region.
	clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
	clientOptions = append(clientOptions, oss.Region("yourRegion"))
	// Set the signature version.
	clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
	client, err := oss.New("yourEndpoint", "", "", clientOptions...)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	list, err := client.DescribeRegions()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	for _, region := range list.Regions {
		// Print the information of all supported regions.
		fmt.Printf("Region:%s\n", region.Region)
		// Print the public (IPv4) Endpoint for each supported region.
		fmt.Printf("Region Internet Endpoint:%s\n", region.InternetEndpoint)
		// Print the internal (classic network or VPC) Endpoint for each supported region.
		fmt.Printf("Region Internal Endpoint:%s\n", region.InternalEndpoint)
		// Print the acceleration endpoint (for global uploads and downloads) for each supported region.
		fmt.Printf("Region Accelerate Endpoint:%s\n", region.AccelerateEndpoint)
	}
	fmt.Println("List Describe Regions Success")
}

Query Endpoint information for a specific region

The following code shows how to query Endpoint information for a specific region.

package main

import (
	"fmt"
	"os"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

func main() {
	// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
	provider, err := oss.NewEnvironmentVariableCredentialsProvider()
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

	// Create an OSSClient instance.
	// Set yourEndpoint to the Endpoint of the bucket. For example, for the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual Endpoint.
	// Set yourRegion to the region where the bucket is located. For example, for the China (Hangzhou) region, set the region to cn-hangzhou. For other regions, specify the actual region.
	clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
	clientOptions = append(clientOptions, oss.Region("yourRegion"))
	// Set the signature version.
	clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
	client, err := oss.New("yourEndpoint", "", "", clientOptions...)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	list, err := client.DescribeRegions(oss.AddParam("regions", "oss-cn-hangzhou"))
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}
	for _, region := range list.Regions {
		// Print the information of the specified region.
		fmt.Printf("Region:%s\n", region.Region)
		// Print the public (IPv4) Endpoint for the specified region.
		fmt.Printf("Region Internet Endpoint:%s\n", region.InternetEndpoint)
		// Print the internal (classic network or VPC) Endpoint for the specified region.
		fmt.Printf("Region Internal Endpoint:%s\n", region.InternalEndpoint)
		// Print the acceleration endpoint (for global uploads and downloads) for the specified region.
		fmt.Printf("Region Accelerate Endpoint:%s\n", region.AccelerateEndpoint)
	}
	fmt.Println("List Describe Regions Success")
}

References

For more information about the API operation used to query Endpoint information, see DescribeRegions.