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.

50 lines
1.4 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. // Notice bucket logging function is testing, can not use.
  8. // BucketLoggingEnabled main struct of logging
  9. type BucketLoggingEnabled struct {
  10. TargetBucket string `xml:"TargetBucket"`
  11. TargetPrefix string `xml:"TargetPrefix"`
  12. }
  13. // BucketPutLoggingOptions is the options of PutBucketLogging
  14. type BucketPutLoggingOptions struct {
  15. XMLName xml.Name `xml:"BucketLoggingStatus"`
  16. LoggingEnabled *BucketLoggingEnabled `xml:"LoggingEnabled,omitempty"`
  17. }
  18. // BucketGetLoggingResult is the result of GetBucketLogging
  19. type BucketGetLoggingResult BucketPutLoggingOptions
  20. // PutBucketLogging https://cloud.tencent.com/document/product/436/17054
  21. func (s *BucketService) PutLogging(ctx context.Context, opt *BucketPutLoggingOptions) (*Response, error) {
  22. sendOpt := sendOptions{
  23. baseURL: s.client.BaseURL.BucketURL,
  24. uri: "/?logging",
  25. method: http.MethodPut,
  26. body: opt,
  27. }
  28. resp, err := s.client.send(ctx, &sendOpt)
  29. return resp, err
  30. }
  31. // GetBucketLogging https://cloud.tencent.com/document/product/436/17053
  32. func (s *BucketService) GetLogging(ctx context.Context) (*BucketGetLoggingResult, *Response, error) {
  33. var res BucketGetLoggingResult
  34. sendOpt := sendOptions{
  35. baseURL: s.client.BaseURL.BucketURL,
  36. uri: "/?logging",
  37. method: http.MethodGet,
  38. result: &res,
  39. }
  40. resp, err := s.client.send(ctx, &sendOpt)
  41. return &res, resp, err
  42. }