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.

69 lines
1.9 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. // BucketTaggingTag is the tag of BucketTagging
  8. type BucketTaggingTag struct {
  9. Key string
  10. Value string
  11. }
  12. // BucketGetTaggingResult is the result of BucketGetTagging
  13. type BucketGetTaggingResult struct {
  14. XMLName xml.Name `xml:"Tagging"`
  15. TagSet []BucketTaggingTag `xml:"TagSet>Tag,omitempty"`
  16. }
  17. // GetTagging 接口实现获取指定Bucket的标签。
  18. //
  19. // https://www.qcloud.com/document/product/436/8277
  20. func (s *BucketService) GetTagging(ctx context.Context) (*BucketGetTaggingResult, *Response, error) {
  21. var res BucketGetTaggingResult
  22. sendOpt := sendOptions{
  23. baseURL: s.client.BaseURL.BucketURL,
  24. uri: "/?tagging",
  25. method: http.MethodGet,
  26. result: &res,
  27. }
  28. resp, err := s.client.doRetry(ctx, &sendOpt)
  29. return &res, resp, err
  30. }
  31. // BucketPutTaggingOptions is the option of BucketPutTagging
  32. type BucketPutTaggingOptions struct {
  33. XMLName xml.Name `xml:"Tagging"`
  34. TagSet []BucketTaggingTag `xml:"TagSet>Tag,omitempty"`
  35. }
  36. // PutTagging 接口实现给用指定Bucket打标签。用来组织和管理相关Bucket。
  37. //
  38. // 当该请求设置相同Key名称,不同Value时,会返回400。请求成功,则返回204。
  39. //
  40. // https://www.qcloud.com/document/product/436/8281
  41. func (s *BucketService) PutTagging(ctx context.Context, opt *BucketPutTaggingOptions) (*Response, error) {
  42. sendOpt := sendOptions{
  43. baseURL: s.client.BaseURL.BucketURL,
  44. uri: "/?tagging",
  45. method: http.MethodPut,
  46. body: opt,
  47. }
  48. resp, err := s.client.doRetry(ctx, &sendOpt)
  49. return resp, err
  50. }
  51. // DeleteTagging 接口实现删除指定Bucket的标签。
  52. //
  53. // https://www.qcloud.com/document/product/436/8286
  54. func (s *BucketService) DeleteTagging(ctx context.Context) (*Response, error) {
  55. sendOpt := sendOptions{
  56. baseURL: s.client.BaseURL.BucketURL,
  57. uri: "/?tagging",
  58. method: http.MethodDelete,
  59. }
  60. resp, err := s.client.doRetry(ctx, &sendOpt)
  61. return resp, err
  62. }