BucketExists verifies if bucket exists and you have permission to access it. Allows for a Context to control cancellations and timeouts.
(ctx context.Context, bucketName string)
| 27 | // BucketExists verifies if bucket exists and you have permission to access it. Allows for a Context to |
| 28 | // control cancellations and timeouts. |
| 29 | func (c *Client) BucketExists(ctx context.Context, bucketName string) (bool, error) { |
| 30 | // Input validation. |
| 31 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 32 | return false, err |
| 33 | } |
| 34 | |
| 35 | // Execute HEAD on bucketName. |
| 36 | resp, err := c.executeMethod(ctx, http.MethodHead, requestMetadata{ |
| 37 | bucketName: bucketName, |
| 38 | contentSHA256Hex: emptySHA256Hex, |
| 39 | }) |
| 40 | defer closeResponse(resp) |
| 41 | if err != nil { |
| 42 | if ToErrorResponse(err).Code == NoSuchBucket { |
| 43 | return false, nil |
| 44 | } |
| 45 | return false, err |
| 46 | } |
| 47 | if resp != nil { |
| 48 | resperr := httpRespToErrorResponse(resp, bucketName, "") |
| 49 | if ToErrorResponse(resperr).Code == NoSuchBucket { |
| 50 | return false, nil |
| 51 | } |
| 52 | if resp.StatusCode != http.StatusOK { |
| 53 | return false, httpRespToErrorResponse(resp, bucketName, "") |
| 54 | } |
| 55 | } |
| 56 | return true, nil |
| 57 | } |
| 58 | |
| 59 | // StatObject verifies if object exists, you have permission to access it |
| 60 | // and returns information about the object. |