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.

53 lines
1.4 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type BucketDomainRule struct {
  8. Status string `xml:"Status,omitempty"`
  9. Name string `xml:"Name,omitempty"`
  10. Type string `xml:"Type,omitempty"`
  11. ForcedReplacement string `xml:"ForcedReplacement,omitempty"`
  12. }
  13. type BucketPutDomainOptions struct {
  14. XMLName xml.Name `xml:"DomainConfiguration"`
  15. Rules []BucketDomainRule `xml:"DomainRule,omitempty"`
  16. }
  17. type BucketGetDomainResult BucketPutDomainOptions
  18. func (s *BucketService) PutDomain(ctx context.Context, opt *BucketPutDomainOptions) (*Response, error) {
  19. sendOpt := &sendOptions{
  20. baseURL: s.client.BaseURL.BucketURL,
  21. uri: "/?domain",
  22. method: http.MethodPut,
  23. body: opt,
  24. }
  25. resp, err := s.client.doRetry(ctx, sendOpt)
  26. return resp, err
  27. }
  28. func (s *BucketService) GetDomain(ctx context.Context) (*BucketGetDomainResult, *Response, error) {
  29. var res BucketGetDomainResult
  30. sendOpt := &sendOptions{
  31. baseURL: s.client.BaseURL.BucketURL,
  32. uri: "/?domain",
  33. method: http.MethodGet,
  34. result: &res,
  35. }
  36. resp, err := s.client.doRetry(ctx, sendOpt)
  37. return &res, resp, err
  38. }
  39. func (s *BucketService) DeleteDomain(ctx context.Context) (*Response, error) {
  40. sendOpt := &sendOptions{
  41. baseURL: s.client.BaseURL.BucketURL,
  42. uri: "/?domain",
  43. method: http.MethodDelete,
  44. }
  45. resp, err := s.client.doRetry(ctx, sendOpt)
  46. return resp, err
  47. }