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.

73 lines
2.3 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 struct {
  27. XMLName xml.Name `xml:"ReplicationConfiguration"`
  28. Role string `xml:"Role"`
  29. Rule []BucketReplicationRule `xml:"Rule"`
  30. }
  31. // PutBucketReplication https://cloud.tencent.com/document/product/436/19223
  32. func (s *BucketService) PutBucketReplication(ctx context.Context, opt *PutBucketReplicationOptions) (*Response, error) {
  33. sendOpt := sendOptions{
  34. baseURL: s.client.BaseURL.BucketURL,
  35. uri: "/?replication",
  36. method: http.MethodPut,
  37. body: opt,
  38. }
  39. resp, err := s.client.send(ctx, &sendOpt)
  40. return resp, err
  41. }
  42. // GetBucketReplication https://cloud.tencent.com/document/product/436/19222
  43. func (s *BucketService) GetBucketReplication(ctx context.Context) (*GetBucketReplicationResult, *Response, error) {
  44. var res GetBucketReplicationResult
  45. sendOpt := sendOptions{
  46. baseURL: s.client.BaseURL.BucketURL,
  47. uri: "/?replication",
  48. method: http.MethodGet,
  49. result: &res,
  50. }
  51. resp, err := s.client.send(ctx, &sendOpt)
  52. return &res, resp, err
  53. }
  54. // DeleteBucketReplication https://cloud.tencent.com/document/product/436/19221
  55. func (s *BucketService) DeleteBucketReplication(ctx context.Context) (*Response, error) {
  56. sendOpt := sendOptions{
  57. baseURL: s.client.BaseURL.BucketURL,
  58. uri: "/?replication",
  59. method: http.MethodDelete,
  60. }
  61. resp, err := s.client.send(ctx, &sendOpt)
  62. return resp, err
  63. }