modulepackage
0.0.0-20190430094544-6b68e9421ecf
Repository: https://github.com/coding/cos-go-sdk-v5.git
Documentation: pkg.go.dev
# README
cos-go-sdk-v5
腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK(API 版本:V5 版本的 XML API)。
Install
go get -u github.com/tencentyun/cos-go-sdk-v5
Usage
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"time"
"github.com/tencentyun/cos-go-sdk-v5"
)
func main() {
//将<bucket>和<region>修改为真实的信息
//bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
u, _ := url.Parse("https://<bucket>.cos.<region>.myqcloud.com")
b := &cos.BaseURL{BucketURL: u}
c := cos.NewClient(b, &http.Client{
//设置超时时间
Timeout: 100 * time.Second,
Transport: &cos.AuthorizationTransport{
//如实填写账号和密钥,也可以设置为环境变量
SecretID: os.Getenv("COS_SECRETID"),
SecretKey: os.Getenv("COS_SECRETKEY"),
},
})
name := "test/hello.txt"
resp, err := c.Object.Get(context.Background(), name, nil)
if err != nil {
panic(err)
}
bs, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
fmt.Printf("%s\n", string(bs))
}
所有的 API 在 example 目录下都有对应的使用示例。
Service API:
- Get Service(使用示例:service/get.go)
Bucket API:
- Get Bucket(使用示例:bucket/get.go)
- Get Bucket ACL(使用示例:bucket/getACL.go)
- Get Bucket CORS(使用示例:bucket/getCORS.go)
- Get Bucket Location(使用示例:bucket/getLocation.go)
- Get Buket Lifecycle(使用示例:bucket/getLifecycle.go)
- Get Bucket Tagging(使用示例:bucket/getTagging.go)
- Put Bucket(使用示例:bucket/put.go)
- Put Bucket ACL(使用示例:bucket/putACL.go)
- Put Bucket CORS(使用示例:bucket/putCORS.go)
- Put Bucket Lifecycle(使用示例:bucket/putLifecycle.go)
- Put Bucket Tagging(使用示例:bucket/putTagging.go)
- Delete Bucket(使用示例:bucket/delete.go)
- Delete Bucket CORS(使用示例:bucket/deleteCORS.go)
- Delete Bucket Lifecycle(使用示例:bucket/deleteLifecycle.go)
- Delete Bucket Tagging(使用示例:bucket/deleteTagging.go)
- Head Bucket(使用示例:bucket/head.go)
- List Multipart Uploads(使用示例:bucket/listMultipartUploads.go)
Object API:
- Get Object(使用示例:object/get.go)
- Get Object ACL(使用示例:object/getACL.go)
- Put Object(使用示例:object/put.go)
- Put Object ACL(使用示例:object/putACL.go)
- Put Object Copy(使用示例:object/copy.go)
- Delete Object(使用示例:object/delete.go)
- Delete Multiple Object(使用示例:object/deleteMultiple.go)
- Head Object(使用示例:object/head.go)
- Options Object(使用示例:object/options.go)
- Initiate Multipart Upload(使用示例:object/initiateMultipartUpload.go)
- Upload Part(使用示例:object/uploadPart.go)
- List Parts(使用示例:object/listParts.go)
- Complete Multipart Upload(使用示例:object/completeMultipartUpload.go)
- Abort Multipart Upload(使用示例:object/abortMultipartUpload.go)
- Mutipart Upload(使用示例:object/MutiUpload.go)
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
AddAuthorizationHeader 给 req 增加签名信息.
NewAuthTime 生成 AuthTime 的便捷函数
expire: 从现在开始多久过期.
NewBucketURL 生成 BaseURL 所需的 BucketURL
bucketName: bucket名称, bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式 Region: 区域代码: ap-beijing-1,ap-beijing,ap-shanghai,ap-guangzhou..
NewClient returns a new COS API client.
# Constants
Version current go sdk version.
# Structs
ACLGrant is the param of ACLXml.
ACLGrantee is the param of ACLGrant.
ACLHeaderOptions is the option of ACLHeader.
ACLXml is the ACL body struct.
AuthorizationTransport 给请求增加 Authorization header.
AuthTime 用于生成签名所需的 q-sign-time 和 q-key-time 相关参数.
BaseURL 访问各 API 所需的基础 URL.
Bucket is the meta info of Bucket.
BucketCORSRule is the rule of BucketCORS.
BucketGetCORSResult is the result of GetBucketCORS.
BucketGetLifecycleResult is the result of BucketGetLifecycle.
BucketGetLocationResult is the result of BucketGetLocation.
BucketGetOptions is the option of GetBucket.
BucketGetResult is the result of GetBucket.
BucketGetTaggingResult is the result of BucketGetTagging.
BucketLifecycleAbortIncompleteMultipartUpload is the param of BucketLifecycleRule.
BucketLifecycleExpiration is the param of BucketLifecycleRule.
BucketLifecycleFilter is the param of BucketLifecycleRule.
BucketLifecycleRule is the rule of BucketLifecycle.
BucketLifecycleTransition is the param of BucketLifecycleRule.
BucketPutACLOptions is the option of PutBucketACL.
BucketPutCORSOptions is the option of PutBucketCORS .
BucketPutLifecycleOptions is the option of PutBucketLifecycle.
BucketPutTaggingOptions is the option of BucketPutTagging.
BucketTaggingTag is the tag of BucketTagging.
CASJobParameters support three way: Standard(in 35 hours), Expedited(quick way, in 15 mins), Bulk(in 5-12 hours_.
Client is a client manages communication with the COS API.
CompleteMultipartUploadOptions is the option of CompleteMultipartUpload.
CompleteMultipartUploadResult is the result CompleteMultipartUpload.
CopyPartHeaderOptions upload part copy request headers.
CopyPartResult upload part copy response.
ErrorResponse 包含 API 返回的错误信息
https://www.qcloud.com/document/product/436/7730.
InitiateMultipartUploadOptions is the option of InitateMultipartUpload.
InitiateMultipartUploadResult is the result of InitateMultipartUpload.
ListMultipartUploadsOptions is the option of ListMultipartUploads.
ListMultipartUploadsResult is the result of ListMultipartUploads.
No description provided by the author
Object is the meta info of the object.
ObjectCopyHeaderOptions is the head option of the Copy.
ObjectCopyOptions is the option of Copy, choose header or body.
ObjectCopyResult is the result of Copy.
ObjectDeleteMultiOptions is the option of DeleteMulti.
ObjectDeleteMultiResult is the result of DeleteMulti.
ObjectGetOptions is the option of GetObject.
ObjectHeadOptions is the option of HeadObject.
ObjectListPartsOptions is the option of ListParts.
ObjectListPartsResult is the result of ListParts.
ObjectOptionsOptions is the option of object options.
ObjectPutACLOptions the options of put object acl.
ObjectPutHeaderOptions the options of header of the put object.
ObjectPutOptions the options of put object.
ObjectRestoreOptions is the option of object restore.
ObjectUploadPartOptions is the options of upload-part.
Owner defines Bucket/Object's owner.
Response API 响应.
ServiceGetResult is the result of Get Service.
# Type aliases
BucketGetACLResult is same to the ACLXml.
BucketPutOptions is same to the ACLHeaderOptions.
BucketService 相关 API.
Initiator same to the Owner struct.
ObjectGetACLResult is the result of GetObjectACL.
ObjectList can used for sort the parts which needs in complete upload part sort.Sort(cos.ObjectList(opt.Parts)).
ObjectService 相关 API.
Service 相关 API.