This topic describes how to use the SDK to call methods for managing data addresses.
Create a data address
The following sample code shows how to create an OSS data address.
Before you create an OSS data address, you must configure a role and obtain the rolename. For more information, see Configure roles.
You can associate a proxy based on your requirements. For more information, see Overview of migration using a proxy. The method for associating proxies is the same for other types of data addresses.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
regionId := "oss-cn-beijing"
bucket := "examplebucket"
prefix := "***/"
roleName := "rolename_xxxxx"
// The list of proxies. You do not need to specify this parameter if you do not need to associate a proxy.
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 sample code shows how to create an OSS Inventory data address.
Before you create an OSS Inventory data address, you must configure roles and obtain the rolename and invrolename. For more information, see Configure roles.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
prefix := "***/"
regionId := "oss-cn-beijing"
bucket := "examplebucket"
roleName := "rolename_xxxxx"
// The following parameters are about 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 sample code shows how to create a general inventory data address.
Before you create an inventory data address, you must configure roles and obtain the rolename and invrolename. For more information, see Configure roles.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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, you can set dataType to oss, s3, cos, obs, tos, qiniu, gcp, azure, ks3, bos, us3, or uss.
dataType := "oss"
// Set the following parameters about the data to migrate based on your actual values.
prefix := "***/"
regionId := "oss-cn-beijing"
bucket := "examplebucket"
roleName := "rolename_xxxxx"
// The following parameters are about 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 sample code shows how to create a data address for a third-party data source.
s3
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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
}
}
cos
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
addressType := "gcp"
accessId := "***"
accessSecret := "******"
// Set the domain parameter based on 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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
}
}
ucloud s3
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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
}
}
Youpai
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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 sample code shows how to create an HTTP data address.
Before you create an HTTP data address, you must configure a role and obtain the invrolename. For more information, see Configure roles.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
addressType := "http"
invDomain := "oss-cn-beijing.aliyuncs.com"
invBucket := "exampleinvbucket"
invLocation := "oss"
invPath := "dir/manifest.json"
invRole := "invrolename_*******"
detail := mgwpackage.AddressDetail{
AddressType: &addressType,
InvDomain: &invDomain,
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 sample code shows how to create a LocalFS data address. A LocalFS data address 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 about the data to migrate based on your actual values.
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
}
}
Get data address details
The following sample code 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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("covert 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": "avaliable",
"VerifyResult": {
"HttpCode": "400",
"ErrorCode": "InvalidArgument",
"ErrorMsg": "Invalid argument."
}
}
}Verify a data address
The following sample code shows how to verify the availability of a specified 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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("covert failed: %v", err)
return
}
// The data address is valid only when the value of the status field is available. Any other value indicates that the data address is invalid.
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 sample code 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 as needed.
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("covert failed: %v", err)
return
}
// The data address is valid only when the value of the status field is available. Any other value indicates that the data address is invalid.
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": "avaliable",
"VerifyResult": {
"HttpCode": "400",
"ErrorCode": "InvalidArgument",
"ErrorMsg": "Invalid argument."
}
}
]
}
}Update a data address
The following sample code shows how to update the proxies associated with a specified data address when you need to scale proxies out or in.
You must specify at least one proxy name. Do not change the proxy channel, or the update will fail.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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 the names of the proxies. Separate multiple names with commas (,). 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 sample code shows how to delete a specified 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"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. Otherwise, your AccessKey pair may be leaked, which compromises 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
}
}
What to do next
After you create a data address, you can create a task. For more information, see Tasks.