All Products
Search
Document Center

Object Storage Service:Use OSS SDK for Go to configure domain names

Last Updated:Dec 12, 2024

This topic describes how to use Object Storage Service (OSS) SDK for Go V2 to configure domain names to access OSS data.

Configure domain names

OSS supports multiple methods to access OSS data. You can select a suitable method based on your actual scenario.

For more information about OSS domain name rules, see OSS domain names.

For more information about the regions and endpoints in OSS, see Regions and endpoints.

Method

Scenario

Method 1: Use a public endpoint to access OSS data

If your applications or services need to access data stored in OSS from all over the world, using a public endpoint is the simplest and most direct method.

Method 2: Use an internal endpoint to access OSS data

If your applications are deployed in a VPC of Alibaba Cloud and need to frequently access OSS data, using an internal endpoint can significantly reduce network latency and bandwidth costs.

Method 3: Use an acceleration endpoint to access OSS data

If your applications require high-speed access to OSS data, especially in cross-region or cross-border scenarios, you can use an acceleration endpoint.

Method 4: Use a dual-stack endpoint to access OSS data

If your network environment supports IPv6 and you need to ensure compatibility with both IPv4 and IPv6 clients, you can use a dual-stack endpoint to seamlessly support both protocols.

Method 5: Use a custom domain name to access OSS data

If you need to manage multiple OSS buckets, you can map different custom domain names to each bucket to facilitate management and maintenance.

Method 6: Use an Apsara Stack domain name to access OSS data

When you use Apsara Stack, you can efficiently access OSS data by using Apsara Stack domain names to ensure data security and reliability during data transmission.

Method 1: Use a public endpoint to access OSS data

Note

You can use the Endpoint parameter to specify the endpoint of a request. If the Endpoint parameter is not specified, OSS SDK for Go creates a public endpoint based on the region. For example, if the value of the Region parameter is cn-hangzhou, oss-cn-hangzhou.aliyuncs.com is created as a public endpoint.

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou")

or

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithEndpoint("oss-cn-hanghzou.aliyuncs.com")

Method 2: Use an internal endpoint to access OSS data

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithUseInternalEndpoint(true)

or

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithEndpoint("oss-cn-hanghzou-internal.aliyuncs.com")

Method 3: Use an acceleration endpoint to access OSS data

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithUseAccelerateEndpoint(true)

or

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithEndpoint("oss-accelerate.aliyuncs.com")

Method 4: Use a dual-stack endpoint to access OSS data

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithUseDualStackEndpoint(true)

or

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithEndpoint("cn-hangzhou.oss.aliyuncs.com")

Method 5: Use a custom domain name to access OSS data

Note

If you use a custom domain name to access OSS data, you must set the WithUseCName parameter to true. When you use a custom domain name to access a bucket, you must map the custom domain name to the default domain name of the bucket. For more information, see Map a custom domain name to the default domain name of a bucket.

The following sample code provides an example on how to map the www.example-***.com domain name to a bucket in the cn-hangzhou region:

cfg := oss.LoadDefaultConfig().
  WithRegion("cn-hangzhou").
  WithEndpoint("www.example-***.com").
  WithUseCName(true)

Method 6: Use an Apsara Stack domain name to access OSS data

var (
  region = "YOUR Region" // Specify the region in which the requested resource is located.
  endpoint = "YOUR Endpoint" // Specify the endpoint of your Apsara Stack or a private region.
)

cfg := oss.LoadDefaultConfig().
  WithRegion(region).
  WithEndpoint(endpoint)

References

For more information about how to configure a domain name, visit Domain names.