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.

71 lines
2.1 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type WebsiteRoutingRule struct {
  8. ConditionErrorCode string `xml:"Condition>HttpErrorCodeReturnedEquals,omitempty"`
  9. ConditionPrefix string `xml:"Condition>KeyPrefixEquals,omitempty"`
  10. RedirectProtocol string `xml:"Redirect>Protocol,omitempty"`
  11. RedirectReplaceKey string `xml:"Redirect>ReplaceKeyWith,omitempty"`
  12. RedirectReplaceKeyPrefix string `xml:"Redirect>ReplaceKeyPrefixWith,omitempty"`
  13. }
  14. type WebsiteRoutingRules struct {
  15. Rules []WebsiteRoutingRule `xml:"RoutingRule,omitempty"`
  16. }
  17. type ErrorDocument struct {
  18. Key string `xml:"Key,omitempty"`
  19. }
  20. type RedirectRequestsProtocol struct {
  21. Protocol string `xml:"Protocol,omitempty"`
  22. }
  23. type BucketPutWebsiteOptions struct {
  24. XMLName xml.Name `xml:"WebsiteConfiguration"`
  25. Index string `xml:"IndexDocument>Suffix"`
  26. RedirectProtocol *RedirectRequestsProtocol `xml:"RedirectAllRequestsTo,omitempty"`
  27. Error *ErrorDocument `xml:"ErrorDocument,omitempty"`
  28. RoutingRules *WebsiteRoutingRules `xml:"RoutingRules,omitempty"`
  29. }
  30. type BucketGetWebsiteResult BucketPutWebsiteOptions
  31. func (s *BucketService) PutWebsite(ctx context.Context, opt *BucketPutWebsiteOptions) (*Response, error) {
  32. sendOpt := &sendOptions{
  33. baseURL: s.client.BaseURL.BucketURL,
  34. uri: "/?website",
  35. method: http.MethodPut,
  36. body: opt,
  37. }
  38. resp, err := s.client.doRetry(ctx, sendOpt)
  39. return resp, err
  40. }
  41. func (s *BucketService) GetWebsite(ctx context.Context) (*BucketGetWebsiteResult, *Response, error) {
  42. var res BucketGetWebsiteResult
  43. sendOpt := &sendOptions{
  44. baseURL: s.client.BaseURL.BucketURL,
  45. uri: "/?website",
  46. method: http.MethodGet,
  47. result: &res,
  48. }
  49. resp, err := s.client.doRetry(ctx, sendOpt)
  50. return &res, resp, err
  51. }
  52. func (s *BucketService) DeleteWebsite(ctx context.Context) (*Response, error) {
  53. sendOpt := &sendOptions{
  54. baseURL: s.client.BaseURL.BucketURL,
  55. uri: "/?website",
  56. method: http.MethodDelete,
  57. }
  58. resp, err := s.client.doRetry(ctx, sendOpt)
  59. return resp, err
  60. }