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.

90 lines
2.8 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type BucketPutOriginOptions struct {
  8. XMLName xml.Name `xml:"OriginConfiguration"`
  9. Rule []BucketOriginRule `xml:"OriginRule"`
  10. }
  11. type BucketOriginRule struct {
  12. OriginType string `xml:"OriginType"`
  13. OriginCondition *BucketOriginCondition `xml:"OriginCondition"`
  14. OriginParameter *BucketOriginParameter `xml:"OriginParameter"`
  15. OriginInfo *BucketOriginInfo `xml:"OriginInfo"`
  16. }
  17. type BucketOriginCondition struct {
  18. HTTPStatusCode string `xml:"HTTPStatusCode,omitempty"`
  19. Prefix string `xml:"Prefix,omitempty"`
  20. }
  21. type BucketOriginParameter struct {
  22. Protocol string `xml:"Protocol,omitempty"`
  23. FollowQueryString bool `xml:"FollowQueryString,omitempty"`
  24. HttpHeader *BucketOriginHttpHeader `xml:"HttpHeader,omitempty"`
  25. FollowRedirection bool `xml:"FollowRedirection,omitempty"`
  26. HttpRedirectCode string `xml:"HttpRedirectCode,omitempty"`
  27. CopyOriginData bool `xml:"CopyOriginData,omitempty"`
  28. }
  29. type BucketOriginHttpHeader struct {
  30. // 目前还不支持 FollowAllHeaders
  31. // FollowAllHeaders bool `xml:"FollowAllHeaders,omitempty"`
  32. NewHttpHeaders []OriginHttpHeader `xml:"NewHttpHeaders>Header,omitempty"`
  33. FollowHttpHeaders []OriginHttpHeader `xml:"FollowHttpHeaders>Header,omitempty"`
  34. }
  35. type OriginHttpHeader struct {
  36. Key string `xml:"Key,omitempty"`
  37. Value string `xml:"Value,omitempty"`
  38. }
  39. type BucketOriginInfo struct {
  40. HostInfo string `xml:"HostInfo>HostName,omitempty"`
  41. FileInfo *BucketOriginFileInfo `xml:"FileInfo,omitempty"`
  42. }
  43. type BucketOriginFileInfo struct {
  44. PrefixDirective bool `xml:"PrefixDirective,omitempty"`
  45. Prefix string `xml:"Prefix,omitempty"`
  46. Suffix string `xml:"Suffix,omitempty"`
  47. }
  48. type BucketGetOriginResult BucketPutOriginOptions
  49. func (s *BucketService) PutOrigin(ctx context.Context, opt *BucketPutOriginOptions) (*Response, error) {
  50. sendOpt := &sendOptions{
  51. baseURL: s.client.BaseURL.BucketURL,
  52. uri: "/?origin",
  53. method: http.MethodPut,
  54. body: opt,
  55. }
  56. resp, err := s.client.send(ctx, sendOpt)
  57. return resp, err
  58. }
  59. func (s *BucketService) GetOrigin(ctx context.Context) (*BucketGetOriginResult, *Response, error) {
  60. var res BucketGetOriginResult
  61. sendOpt := &sendOptions{
  62. baseURL: s.client.BaseURL.BucketURL,
  63. uri: "/?origin",
  64. method: http.MethodGet,
  65. result: &res,
  66. }
  67. resp, err := s.client.send(ctx, sendOpt)
  68. return &res, resp, err
  69. }
  70. func (s *BucketService) DeleteOrigin(ctx context.Context) (*Response, error) {
  71. sendOpt := &sendOptions{
  72. baseURL: s.client.BaseURL.BucketURL,
  73. uri: "/?origin",
  74. method: http.MethodDelete,
  75. }
  76. resp, err := s.client.send(ctx, sendOpt)
  77. return resp, err
  78. }