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
2.1 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. // ReplicationDestination is the sub struct of BucketReplicationRule
  8. type ReplicationDestination struct {
  9. Bucket string `xml:"Bucket"`
  10. StorageClass string `xml:"StorageClass,omitempty"`
  11. }
  12. // BucketReplicationRule is the main param of replication
  13. type BucketReplicationRule struct {
  14. ID string `xml:"ID,omitempty"`
  15. Status string `xml:"Status"`
  16. Prefix string `xml:"Prefix"`
  17. Destination *ReplicationDestination `xml:"Destination"`
  18. }
  19. // PutBucketReplicationOptions is the options of PutBucketReplication
  20. type PutBucketReplicationOptions struct {
  21. XMLName xml.Name `xml:"ReplicationConfiguration"`
  22. Role string `xml:"Role"`
  23. Rule []BucketReplicationRule `xml:"Rule"`
  24. }
  25. // GetBucketReplicationResult is the result of GetBucketReplication
  26. type GetBucketReplicationResult PutBucketReplicationOptions
  27. // PutBucketReplication https://cloud.tencent.com/document/product/436/19223
  28. func (s *BucketService) PutBucketReplication(ctx context.Context, opt *PutBucketReplicationOptions) (*Response, error) {
  29. sendOpt := sendOptions{
  30. baseURL: s.client.BaseURL.BucketURL,
  31. uri: "/?replication",
  32. method: http.MethodPut,
  33. body: opt,
  34. }
  35. resp, err := s.client.doRetry(ctx, &sendOpt)
  36. return resp, err
  37. }
  38. // GetBucketReplication https://cloud.tencent.com/document/product/436/19222
  39. func (s *BucketService) GetBucketReplication(ctx context.Context) (*GetBucketReplicationResult, *Response, error) {
  40. var res GetBucketReplicationResult
  41. sendOpt := sendOptions{
  42. baseURL: s.client.BaseURL.BucketURL,
  43. uri: "/?replication",
  44. method: http.MethodGet,
  45. result: &res,
  46. }
  47. resp, err := s.client.doRetry(ctx, &sendOpt)
  48. return &res, resp, err
  49. }
  50. // DeleteBucketReplication https://cloud.tencent.com/document/product/436/19221
  51. func (s *BucketService) DeleteBucketReplication(ctx context.Context) (*Response, error) {
  52. sendOpt := sendOptions{
  53. baseURL: s.client.BaseURL.BucketURL,
  54. uri: "/?replication",
  55. method: http.MethodDelete,
  56. }
  57. resp, err := s.client.doRetry(ctx, &sendOpt)
  58. return resp, err
  59. }