getBucketLocation - Get location for the bucketName from location map cache, if not fetch freshly by making a new request.
(ctx context.Context, bucketName string)
| 41 | // getBucketLocation - Get location for the bucketName from location map cache, if not |
| 42 | // fetch freshly by making a new request. |
| 43 | func (c *Client) getBucketLocation(ctx context.Context, bucketName string) (string, error) { |
| 44 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 45 | return "", err |
| 46 | } |
| 47 | |
| 48 | // Region set then no need to fetch bucket location. |
| 49 | if c.region != "" { |
| 50 | return c.region, nil |
| 51 | } |
| 52 | |
| 53 | if location, ok := c.bucketLocCache.Get(bucketName); ok { |
| 54 | return location, nil |
| 55 | } |
| 56 | |
| 57 | // Initialize a new request. |
| 58 | req, err := c.getBucketLocationRequest(ctx, bucketName) |
| 59 | if err != nil { |
| 60 | return "", err |
| 61 | } |
| 62 | |
| 63 | // Initiate the request. |
| 64 | resp, err := c.do(req) |
| 65 | defer closeResponse(resp) |
| 66 | if err != nil { |
| 67 | return "", err |
| 68 | } |
| 69 | location, err := processBucketLocationResponse(resp, bucketName) |
| 70 | if err != nil { |
| 71 | return "", err |
| 72 | } |
| 73 | c.bucketLocCache.Set(bucketName, location) |
| 74 | return location, nil |
| 75 | } |
| 76 | |
| 77 | // processes the getBucketLocation http response from the server. |
| 78 | func processBucketLocationResponse(resp *http.Response, bucketName string) (bucketLocation string, err error) { |
no test coverage detected