This topic describes how to use the SDK for Go to create, retrieve, verify, list, update, and delete data addresses for Data Online Migration.
Create a data address
The following code example shows how to create an OSS data address.
Before you create an OSS data address, you must configure a role and obtain the role name (
rolename).Whether you need to associate a proxy depends on your specific scenario. For more information, see Overview of migration using a proxy. The association method is the same for other data address types.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
addressType := "oss"
// Set the following parameters based on your source data.
regionId := "oss-cn-beijing"
bucket := "examplebucket"
prefix := "***/"
roleName := "rolename_xxxxx"
// The list of proxies. Omit this parameter if no proxy association is required.
agentList := "agent1,agent2,agent3"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
RegionId: ®ionId,
Bucket: &bucket,
Prefix: &prefix,
Role: &roleName,
AgentList: &agentList,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
The following code example shows how to create an OSS Inventory data address.
Before you create an OSS Inventory data address, you must configure roles and obtain both the role name (rolename) and the inventory role name (invrolename).
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
addressType := "ossinv"
// Set the following parameters based on your source data.
prefix := "***/"
regionId := "oss-cn-beijing"
bucket := "examplebucket"
roleName := "rolename_xxxxx"
// The following parameters define the inventory.
invLocation := "oss"
invBucket := "exampleinvbucket"
invRegionId := "oss-cn-beijing"
invRole := "invrolename_*******"
invPath := "dir/manifest.json"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
RegionId: ®ionId,
Bucket: &bucket,
Prefix: &prefix,
Role: &roleName,
InvLocation: &invLocation,
InvBucket: &invBucket,
InvRegionId: &invRegionId,
InvRole: &invRole,
InvPath: &invPath,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
The following code example shows how to create a general inventory data address.
Before you create a general inventory data address, you must configure roles and obtain both the role name (rolename) and the inventory role name (invrolename).
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
addressType := "inv"
// If addressType is set to inv, valid values for dataType include oss, s3, cos, obs, tos, qiniu, GCP, Azure, ks3, bos, us3, and uss.
dataType := "oss"
// Set the following parameters based on your source data.
prefix := "***/"
regionId := "oss-cn-beijing"
bucket := "examplebucket"
roleName := "rolename_xxxxx"
// The following parameters define the inventory.
invLocation := "oss"
invBucket := "exampleinvbucket"
invRegionId := "oss-cn-beijing"
invRole := "invrolename_*******"
invPath := "dir/manifest.json"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
DataType: &dataType,
RegionId: ®ionId,
Bucket: &bucket,
Prefix: &prefix,
Role: &roleName,
InvLocation: &invLocation,
InvBucket: &invBucket,
InvRegionId: &invRegionId,
InvRole: &invRole,
InvPath: &invPath,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
The following code examples show how to create data addresses for third-party sources.
S3
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "s3"
accessId := "***"
accessSecret := "******"
domain := "s3.ap-southeast-1.amazonaws.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
S3 compatible
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "s3compat"
accessId := "***"
accessSecret := "******"
domain := "<s3 compat url>"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
UCloud US3
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "us3"
accessId := "***"
accessSecret := "******"
domain := "cn-bj.ufileos.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
COS
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "cos"
accessId := "***"
accessSecret := "******"
domain := "cos.ap-nanjing.myqcloud.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
OBS
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "obs"
accessId := "***"
accessSecret := "******"
domain := "obs.cn-north-1.myhuaweicloud.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
TOS
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "tos"
accessId := "***"
accessSecret := "******"
domain := "tos-s3-cn-beijing.volces.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
Qiniu
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "qiniu"
accessId := "***"
accessSecret := "******"
// For more information about domain names, see https://developer.qiniu.com/kodo/8527/kodo-domain-name-management
domain := "http://xxxx.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
GCP
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "gcp"
accessId := "***"
accessSecret := "******"
// Set the domain parameter to your actual value.
domain := "Cloud Storage URI"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
Azure
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "azure"
accessSecret := "******"
domain := "https://<storage-account>.blob.core.windows.net"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
KS3
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "ks3"
accessId := "***"
accessSecret := "******"
domain := "ks3-cn-beijing.ksyuncs.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
BOS
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "bos"
accessId := "***"
accessSecret := "******"
domain := "bj.bcebos.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
UPYUN
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "uss"
accessId := "***"
accessSecret := "******"
domain := "s3.api.upyun.com"
bucket := "examplebucket"
prefix := "***/"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
AccessId: &accessId,
AccessSecret: &accessSecret,
Domain: &domain,
Bucket: &bucket,
Prefix: &prefix,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
The following code example shows how to create an HTTP data address.
Before you create an HTTP data address, you must configure a role for the inventory and obtain its name (invrolename).
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "http"
invRegionId := "oss-cn-beijing"
invBucket := "exampleinvbucket"
invLocation := "oss"
invPath := "dir/manifest.json"
invRole := "invrolename_*******"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
InvRegionId: &invRegionId,
InvLocation: &invLocation,
InvPath: &invPath,
InvRole: &invRole,
InvBucket: &invBucket,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
The following code example shows how to create a LocalFS data address, which must be associated with a proxy.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
address := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameters based on your source data.
addressType := "local"
prefix := "/***/"
// The list of proxies.
agentList := "agent1,agent2,agent3"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
Prefix: &prefix,
AgentList: &agentList,
}
_, err = client.CreateAddress(&userId, &mgwpackage.CreateAddressRequest{
ImportAddress: &mgwpackage.CreateAddressInfo{
Name: &address,
AddressDetail: &detail,
}})
if err != nil {
log.Printf("create address failed: %v", err)
return
}
}
Retrieve data address details
The following code example shows how to retrieve the details of a data address.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
addressName := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetAddress(&userId, &addressName)
if err != nil {
log.Printf("get address failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample response
{
"ImportAddress": {
"Owner": "test_owner",
"Name": "test_name",
"AddressDetail": {
"AddressType": "ossinv",
"Bucket": "test_bucket",
"Domain": "test_domain",
"Prefix": "test_prefix",
"AccessId": "test_access_id",
"AccessSecret": "test_secret_key",
"Role": "test_role",
"InvDomain": "test_inv_domain",
"InvBucket": "test_inv_bucket",
"InvAccessId": "test_inv_access_id",
"InvAccessSecret": "test_inv_secret_key",
"InvPath": "manifest.json",
"InvRole": "test_inv_role",
"InvLocation": "oss",
"AgentList": "agent1,agent2",
"RegionId": "test_region_id",
"InvRegionId": "test_inv_region_id"
},
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"VerifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Tags": "K1:V1,K2:V2",
"Status": "available",
"VerifyResult": {
"HttpCode": "400",
"ErrorCode": "InvalidArgument",
"ErrorMsg": "Invalid argument."
}
}
}Verify a data address
The following code example shows how to verify a data address.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
addressName := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.VerifyAddress(&userId, &addressName)
if err != nil {
log.Printf("verify address failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
// The data address is valid only if the `Status` field is `available`.
fmt.Println(string(jsonBytes))
}
Sample response for an available address
{
"VerifyAddressResponse": {
"Status": "available",
"VerifyTime": "2024-05-01T12:00:00.000Z",
"ErrorCode": "",
"ErrorMessage": ""
}
}Sample response for an unavailable address
{
"VerifyAddressResponse": {
"Status": "unavailable",
"VerifyTime": "2024-05-01T12:00:00.000Z",
"ErrorCode": "400",
"ErrorMessage": "Invalid argument."
}
}List data addresses
The following code example shows how to list all data addresses in your account.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the `marker` and `count` parameters based on your requirements.
count := int32(1)
marker := ""
resp, err := client.ListAddress(&userId, &mgwpackage.ListAddressRequest{
Count: &count, Marker: &marker,
})
if err != nil {
log.Printf("list address failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("convert failed: %v", err)
return
}
// The data address is valid only if the `Status` field is `available`.
fmt.Println(string(jsonBytes))
}
Sample response
{
"ImportAddressList": {
"Truncated": true,
"NextMarker": "test_marker",
"ImportAddress": [
{
"Owner": "test_owner",
"Name": "test_name",
"AddressDetail": {
"AddressType": "ossinv",
"Bucket": "test_bucket",
"Domain": "test_domain",
"Prefix": "test_prefix",
"AccessId": "test_access_id",
"AccessSecret": "test_secret_key",
"Role": "test_role",
"InvDomain": "test_inv_domain",
"InvBucket": "test_inv_bucket",
"InvAccessId": "test_inv_access_id",
"InvAccessSecret": "test_inv_secret_key",
"InvPath": "manifest.json",
"InvRole": "test_inv_role",
"InvLocation": "oss",
"AgentList": "agent1,agent2",
"RegionId": "test_region_id",
"InvRegionId": "test_inv_region_id"
},
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"VerifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Tags": "K1:V1,K2:V2",
"Status": "available",
"VerifyResult": {
"HttpCode": "400",
"ErrorCode": "InvalidArgument",
"ErrorMsg": "Invalid argument."
}
}
]
}
}Update a data address
The following code example shows how to update the proxies associated with a specified data address. This is useful for scaling proxies.
You must specify at least one proxy name. Do not change the proxy channel, as this will cause the update to fail.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
addressName := "exampleaddress"
// Specify a comma-separated list of proxy names. This parameter cannot be empty.
agentList := "exampleagent1,exampleagent2,exampleagent3..."
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.UpdateAddress(&userId, &addressName, &mgwpackage.UpdateAddressRequest{
ImportAddress: &mgwpackage.UpdateAddressInfo{
AgentList: &agentList,
},
})
if err != nil {
log.Printf("update address failed: %v", err)
return
}
}
Delete a data address
The following code example shows how to delete a data address.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** We strongly recommend that you do not save your AccessKey ID and AccessKey Secret in your project code. If you do, you risk leaking your AccessKey pair, which would compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Specify the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify this parameter, HTTPS is used by default.
protocol := "http"
// Specify the name of the data address.
addressName := "exampleaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.DeleteAddress(&userId, &addressName)
if err != nil {
log.Printf("delete address failed: %v", err)
return
}
}
Next steps
After you create a data address, you can create a migration task. For more information, see Tasks.