You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.7 KiB

3 years ago
3 years ago
4 years ago
4 years ago
  1. # cos-go-sdk-v5
  2. 腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK(API 版本:V5 版本的 XML API)。
  3. ## Install
  4. `go get -u git.ouxuan.net/tommy/cos-go-sdk-v5`
  5. ## Usage
  6. ```go
  7. package main
  8. import (
  9. "context"
  10. "fmt"
  11. "io/ioutil"
  12. "net/http"
  13. "net/url"
  14. "os"
  15. "time"
  16. "git.ouxuan.net/tommy/cos-go-sdk-v5"
  17. )
  18. func main() {
  19. //将<bucket><region>修改为真实的信息
  20. //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
  21. u, _ := url.Parse("https://<bucket>.cos.<region>.myqcloud.com")
  22. b := &cos.BaseURL{BucketURL: u}
  23. c := cos.NewClient(b, &http.Client{
  24. //设置超时时间
  25. Timeout: 100 * time.Second,
  26. Transport: &cos.AuthorizationTransport{
  27. //如实填写账号和密钥,也可以设置为环境变量
  28. SecretID: os.Getenv("COS_SECRETID"),
  29. SecretKey: os.Getenv("COS_SECRETKEY"),
  30. },
  31. })
  32. name := "test/hello.txt"
  33. resp, err := c.Object.Get(context.Background(), name, nil)
  34. if err != nil {
  35. panic(err)
  36. }
  37. bs, _ := ioutil.ReadAll(resp.Body)
  38. resp.Body.Close()
  39. fmt.Printf("%s\n", string(bs))
  40. }
  41. ```
  42. 所有的 API 在 [example](./example/) 目录下都有对应的使用示例。
  43. Service API:
  44. * [x] Get Service(使用示例:[service/get.go](./example/service/get.go))
  45. Bucket API:
  46. * [x] Get Bucket(使用示例:[bucket/get.go](./example/bucket/get.go))
  47. * [x] Get Bucket ACL(使用示例:[bucket/getACL.go](./example/bucket/getACL.go))
  48. * [x] Get Bucket CORS(使用示例:[bucket/getCORS.go](./example/bucket/getCORS.go))
  49. * [x] Get Bucket Location(使用示例:[bucket/getLocation.go](./example/bucket/getLocation.go))
  50. * [x] Get Buket Lifecycle(使用示例:[bucket/getLifecycle.go](./example/bucket/getLifecycle.go))
  51. * [x] Get Bucket Tagging(使用示例:[bucket/getTagging.go](./example/bucket/getTagging.go))
  52. * [x] Put Bucket(使用示例:[bucket/put.go](./example/bucket/put.go))
  53. * [x] Put Bucket ACL(使用示例:[bucket/putACL.go](./example/bucket/putACL.go))
  54. * [x] Put Bucket CORS(使用示例:[bucket/putCORS.go](./example/bucket/putCORS.go))
  55. * [x] Put Bucket Lifecycle(使用示例:[bucket/putLifecycle.go](./example/bucket/putLifecycle.go))
  56. * [x] Put Bucket Tagging(使用示例:[bucket/putTagging.go](./example/bucket/putTagging.go))
  57. * [x] Delete Bucket(使用示例:[bucket/delete.go](./example/bucket/delete.go))
  58. * [x] Delete Bucket CORS(使用示例:[bucket/deleteCORS.go](./example/bucket/deleteCORS.go))
  59. * [x] Delete Bucket Lifecycle(使用示例:[bucket/deleteLifecycle.go](./example/bucket/deleteLifecycle.go))
  60. * [x] Delete Bucket Tagging(使用示例:[bucket/deleteTagging.go](./example/bucket/deleteTagging.go))
  61. * [x] Head Bucket(使用示例:[bucket/head.go](./example/bucket/head.go))
  62. * [x] List Multipart Uploads(使用示例:[bucket/listMultipartUploads.go](./example/bucket/listMultipartUploads.go))
  63. Object API:
  64. * [x] Get Object(使用示例:[object/get.go](./example/object/get.go))
  65. * [x] Get Object ACL(使用示例:[object/getACL.go](./example/object/getACL.go))
  66. * [x] Put Object(使用示例:[object/put.go](./example/object/put.go))
  67. * [x] Put Object ACL(使用示例:[object/putACL.go](./example/object/putACL.go))
  68. * [x] Put Object Copy(使用示例:[object/copy.go](./example/object/copy.go))
  69. * [x] Delete Object(使用示例:[object/delete.go](./example/object/delete.go))
  70. * [x] Delete Multiple Object(使用示例:[object/deleteMultiple.go](./example/object/deleteMultiple.go))
  71. * [x] Head Object(使用示例:[object/head.go](./example/object/head.go))
  72. * [x] Options Object(使用示例:[object/options.go](./example/object/options.go))
  73. * [x] Initiate Multipart Upload(使用示例:[object/initiateMultipartUpload.go](./example/object/initiateMultipartUpload.go))
  74. * [x] Upload Part(使用示例:[object/uploadPart.go](./example/object/uploadPart.go))
  75. * [x] List Parts(使用示例:[object/listParts.go](./example/object/listParts.go))
  76. * [x] Complete Multipart Upload(使用示例:[object/completeMultipartUpload.go](./example/object/completeMultipartUpload.go))
  77. * [x] Abort Multipart Upload(使用示例:[object/abortMultipartUpload.go](./example/object/abortMultipartUpload.go))
  78. * [x] Mutipart Upload(使用示例:[object/MutiUpload.go](./example/object/MutiUpload.go))
  79. 数据处理 API:
  80. * [x] 媒体处理(使用示例:[media_process.go](./example/CI/media_process/media_process.go))
  81. * [x] 文档处理(使用示例:[ci_doc_process.go](./example/CI/doc_process/ci_doc_process.go))
  82. 内容审核 API:
  83. * [x] 视频审核(使用示例:[ci_video_auditing_job.go](./example/CI/content_auditing/ci_video_auditing_job.go))