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.

75 lines
1.9 KiB

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