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.

54 lines
1008 B

  1. package main
  2. import (
  3. "context"
  4. "net/url"
  5. "os"
  6. "time"
  7. "net/http"
  8. "github.com/tencentyun/cos-go-sdk-v5"
  9. "github.com/tencentyun/cos-go-sdk-v5/debug"
  10. )
  11. func main() {
  12. u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
  13. b := &cos.BaseURL{
  14. BucketURL: u,
  15. }
  16. c := cos.NewClient(b, &http.Client{
  17. Transport: &cos.AuthorizationTransport{
  18. SecretID: os.Getenv("COS_SECRETID"),
  19. SecretKey: os.Getenv("COS_SECRETKEY"),
  20. Transport: &debug.DebugRequestTransport{
  21. RequestHeader: true,
  22. RequestBody: true,
  23. ResponseHeader: true,
  24. ResponseBody: true,
  25. },
  26. },
  27. })
  28. startTime := time.Now()
  29. tg := &cos.BucketPutTaggingOptions{
  30. TagSet: []cos.BucketTaggingTag{
  31. {
  32. Key: "test_k2",
  33. Value: "test_v2",
  34. },
  35. {
  36. Key: "test_k3",
  37. Value: "test_v3",
  38. },
  39. {
  40. Key: startTime.Format("02_Jan_06_15_04_MST"),
  41. Value: "test_time",
  42. },
  43. },
  44. }
  45. _, err := c.Bucket.PutTagging(context.Background(), tg)
  46. if err != nil {
  47. panic(err)
  48. }
  49. }