阅读本文,您可以获取 Go SDK 资源管理的接口调用示例,实现快速开发。
调用接口前,请先完成 Go SDK 的安装及初始化操作。
本节为您介绍资源管理相关接口的功能和调用示例。
您可以调用 UpdateImageFileKey 接口通过指定源文件的 storekey 来对指定文件进行重命名操作。详细的参数说明可参见 UpdateImageFileKey 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_UpdateImageFileKey(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.UpdateImageFileKeyReq{ UpdateImageFileKeyQuery: &imagex.UpdateImageFileKeyQuery{}, UpdateImageFileKeyBody: &imagex.UpdateImageFileKeyBody{}, } resp, err := instance.UpdateImageFileKey(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageStorageFiles 接口列举并返回服务对应存储下的全量资源,并按照 Key 的字典序返回。详细的参数说明可参见 GetImageStorageFiles 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageStorageFiles(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageStorageFilesQuery{} resp, err := instance.GetImageStorageFiles(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageUploadFile 接口指定服务 ID 以及已上传的文件 Uri,来获取上传文件的详细信息。详细的参数说明可参见 GetImageUploadFile 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageUploadFile(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageUploadFileQuery{} resp, err := instance.GetImageUploadFile(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetImageUploadFiles 接口获取当前服务下全部的上传文件信息。详细的参数说明可参见 GetImageUploadFiles 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetImageUploadFiles(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetImageUploadFilesQuery{} resp, err := instance.GetImageUploadFiles(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 DeleteImageUploadFiles 接口删除指定的文件。详细的参数说明可参见 DeleteImageUploadFiles 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_DeleteImageUploadFiles(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.DeleteImageUploadFilesReq{ DeleteImageUploadFilesQuery: &imagex.DeleteImageUploadFilesQuery{}, DeleteImageUploadFilesBody: &imagex.DeleteImageUploadFilesBody{}, } resp, err := instance.DeleteImageUploadFiles(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 PreviewImageUploadFile 接口获取指定文件的详细信息。详细的参数说明可参见 PreviewImageUploadFile 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_PreviewImageUploadFile(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.PreviewImageUploadFileQuery{} resp, err := instance.PreviewImageUploadFile(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetResourceURL 接口获取指定服务即域名的资源地址。详细的参数说明可参见 GetResourceURL 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetResourceURL(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetResourceURLQuery{} resp, err := instance.GetResourceURL(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 FetchImageUrl 接口对待迁移文件资源进行抓取和上传,并获取迁移后文件 URI。详细的参数说明可参见 FetchImageUrl 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_FetchImageURL(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.FetchImageURLBody{} resp, err := instance.FetchImageURL(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetUrlFetchTask 接口通过异步 Fetch 任务 ID,获取异步任务详情。详细的参数说明可参见 GetUrlFetchTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetURLFetchTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetURLFetchTaskQuery{} resp, err := instance.GetURLFetchTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 CreateImageCompressTask 接口指定压缩文件/文件夹及其他配置创建异步压缩任务,系统将执行压缩打包处理并将压缩包存储至指定服务内。详细的参数说明可参见 CreateImageCompressTask 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_CreateImageCompressTask(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.CreateImageCompressTaskReq{ CreateImageCompressTaskQuery: &imagex.CreateImageCompressTaskQuery{}, CreateImageCompressTaskBody: &imagex.CreateImageCompressTaskBody{}, } resp, err := instance.CreateImageCompressTask(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 GetCompressTaskInfo 接口获取压缩任务详情。详细的参数说明可参见 GetCompressTaskInfo 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_GetCompressTaskInfo(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.GetCompressTaskInfoQuery{} resp, err := instance.GetCompressTaskInfo(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 UpdateImageResourceStatus 接口修改指定服务下资源的封禁状态。详细的参数说明可参见 UpdateImageResourceStatus 接口文档。
接口调用示例如下所示。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_UpdateImageResourceStatus(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.UpdateImageResourceStatusReq{ UpdateImageResourceStatusQuery: &imagex.UpdateImageResourceStatusQuery{}, UpdateImageResourceStatusBody: &imagex.UpdateImageResourceStatusBody{}, } resp, err := instance.UpdateImageResourceStatus(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }
您可以调用 CreateImageFromUri 接口源服务内的存储资源,复制到目标服务中。详细的参数说明可参见 CreateImageFromUri 接口文档。
package imagex_test import ( "context" "encoding/json" "fmt" "testing" "github.com/volcengine/volc-sdk-golang/base" imagex "github.com/volcengine/volc-sdk-golang/service/imagex/v2" ) func Test_CreateImageFromURI(t *testing.T) { instance := imagex.NewInstance() instance.SetCredential(base.Credentials{ AccessKeyID: "ak", SecretAccessKey: "sk", }) param := &imagex.CreateImageFromURIReq{ CreateImageFromURIQuery: &imagex.CreateImageFromURIQuery{}, CreateImageFromURIBody: &imagex.CreateImageFromURIBody{}, } resp, err := instance.CreateImageFromURI(context.Background(), param) if err != nil { fmt.Printf("error %v", err) } else { t, _ := json.Marshal(resp) fmt.Printf("success %v", string(t)) } }