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.

77 lines
2.1 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. // BucketCORSRule ...
  8. type BucketCORSRule struct {
  9. ID string `xml:"ID,omitempty"`
  10. AllowedMethods []string `xml:"AllowedMethod"`
  11. AllowedOrigins []string `xml:"AllowedOrigin"`
  12. AllowedHeaders []string `xml:"AllowedHeader,omitempty"`
  13. MaxAgeSeconds int `xml:"MaxAgeSeconds,omitempty"`
  14. ExposeHeaders []string `xml:"ExposeHeader,omitempty"`
  15. }
  16. // BucketGetCORSResult ...
  17. type BucketGetCORSResult struct {
  18. XMLName xml.Name `xml:"CORSConfiguration"`
  19. Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
  20. }
  21. // GetCORS ...
  22. //
  23. // Get Bucket CORS实现跨域访问配置读取。
  24. //
  25. // https://www.qcloud.com/document/product/436/8274
  26. func (s *BucketService) GetCORS(ctx context.Context) (*BucketGetCORSResult, *Response, error) {
  27. var res BucketGetCORSResult
  28. sendOpt := sendOptions{
  29. baseURL: s.client.BaseURL.BucketURL,
  30. uri: "/?cors",
  31. method: http.MethodGet,
  32. result: &res,
  33. }
  34. resp, err := s.client.send(ctx, &sendOpt)
  35. return &res, resp, err
  36. }
  37. // BucketPutCORSOptions ...
  38. type BucketPutCORSOptions struct {
  39. XMLName xml.Name `xml:"CORSConfiguration"`
  40. Rules []BucketCORSRule `xml:"CORSRule,omitempty"`
  41. }
  42. // PutCORS ...
  43. //
  44. // Put Bucket CORS实现跨域访问设置,您可以通过传入XML格式的配置文件实现配置,文件大小限制为64 KB。
  45. //
  46. // https://www.qcloud.com/document/product/436/8279
  47. func (s *BucketService) PutCORS(ctx context.Context, opt *BucketPutCORSOptions) (*Response, error) {
  48. sendOpt := sendOptions{
  49. baseURL: s.client.BaseURL.BucketURL,
  50. uri: "/?cors",
  51. method: http.MethodPut,
  52. body: opt,
  53. }
  54. resp, err := s.client.send(ctx, &sendOpt)
  55. return resp, err
  56. }
  57. // DeleteCORS ...
  58. //
  59. // Delete Bucket CORS实现跨域访问配置删除。
  60. //
  61. // https://www.qcloud.com/document/product/436/8283
  62. func (s *BucketService) DeleteCORS(ctx context.Context) (*Response, error) {
  63. sendOpt := sendOptions{
  64. baseURL: s.client.BaseURL.BucketURL,
  65. uri: "/?cors",
  66. method: http.MethodDelete,
  67. }
  68. resp, err := s.client.send(ctx, &sendOpt)
  69. return resp, err
  70. }