A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to query the region of a bucket.
The following code provides an example on how to query the region or location of a bucket:
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Create an OSSClient instance.
client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Query the region of the bucket.
loc, err := client.GetBucketLocation("<yourBucketName>")
if err ! = nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println("Bucket Location:", loc)
}
For more information about regions, see GetBucketLocation and the "region" section in Terms in OSS Developer Guide.