bucket_location.go 612 B

123456789101112131415161718192021222324252627
  1. package s3
  2. import (
  3. "github.com/ks3sdklib/aws-sdk-go/aws"
  4. "github.com/ks3sdklib/aws-sdk-go/aws/awserr"
  5. "io"
  6. "regexp"
  7. )
  8. var reBucketLocation = regexp.MustCompile(`>([^<>]+)<\/LocationConstraint`)
  9. func buildGetBucketLocation(r *aws.Request) {
  10. if r.DataFilled() {
  11. out := r.Data.(*GetBucketLocationOutput)
  12. b, err := io.ReadAll(r.HTTPResponse.Body)
  13. if err != nil {
  14. r.Error = awserr.New("Unmarshal",
  15. "failed reading response body", err)
  16. return
  17. }
  18. match := reBucketLocation.FindSubmatch(b)
  19. if len(match) > 1 {
  20. loc := string(match[1])
  21. out.LocationConstraint = aws.String(loc)
  22. }
  23. }
  24. }