MCPcopy
hub / github.com/minio/minio-go / BucketExists

Method BucketExists

api-stat.go:29–57  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

27// BucketExists verifies if bucket exists and you have permission to access it. Allows for a Context to
28// control cancellations and timeouts.
29func (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.

Callers 6

testFunctionalFunction · 0.95
testFunctionalV2Function · 0.95
TestHealthCheckFunction · 0.80
TestGetBucketPolicyFunction · 0.80
runFunction · 0.80
mainFunction · 0.80

Calls 5

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
ToErrorResponseFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70

Tested by 2

TestHealthCheckFunction · 0.64
TestGetBucketPolicyFunction · 0.64