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

Method doMakeBucket

api-put-bucket.go:46–108  ·  view source on GitHub ↗
(ctx context.Context, bucketName string, opts MakeBucketOptions)

Source from the content-addressed store, hash-verified

44}
45
46func (c *Client) doMakeBucket(ctx context.Context, bucketName string, opts MakeBucketOptions) (err error) {
47 defer func() {
48 // Save the location into cache on a successful makeBucket response.
49 if err == nil {
50 c.bucketLocCache.Set(bucketName, opts.Region)
51 }
52 }()
53
54 // If location is empty, treat is a default region 'us-east-1'.
55 if opts.Region == "" {
56 opts.Region = "us-east-1"
57 // For custom region clients, default
58 // to custom region instead not 'us-east-1'.
59 if c.region != "" {
60 opts.Region = c.region
61 }
62 }
63 // PUT bucket request metadata.
64 reqMetadata := requestMetadata{
65 bucketName: bucketName,
66 bucketLocation: opts.Region,
67 }
68
69 headers := make(http.Header)
70 if opts.ObjectLocking {
71 headers.Add("x-amz-bucket-object-lock-enabled", "true")
72 }
73 if opts.ForceCreate {
74 headers.Add("x-minio-force-create", "true")
75 }
76 reqMetadata.customHeader = headers
77
78 // If location is not 'us-east-1' create bucket location config.
79 if opts.Region != "us-east-1" && opts.Region != "" {
80 createBucketConfig := createBucketConfiguration{}
81 createBucketConfig.Location = opts.Region
82 var createBucketConfigBytes []byte
83 createBucketConfigBytes, err = xml.Marshal(createBucketConfig)
84 if err != nil {
85 return err
86 }
87 reqMetadata.contentMD5Base64 = sumMD5Base64(createBucketConfigBytes)
88 reqMetadata.contentSHA256Hex = sum256Hex(createBucketConfigBytes)
89 reqMetadata.contentBody = bytes.NewReader(createBucketConfigBytes)
90 reqMetadata.contentLength = int64(len(createBucketConfigBytes))
91 }
92
93 // Execute PUT to create a new bucket.
94 resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
95 defer closeResponse(resp)
96 if err != nil {
97 return err
98 }
99
100 if resp != nil {
101 if resp.StatusCode != http.StatusOK {
102 return httpRespToErrorResponse(resp, bucketName, "")
103 }

Callers 1

makeBucketMethod · 0.95

Calls 8

executeMethodMethod · 0.95
sumMD5Base64Function · 0.85
sum256HexFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
MarshalMethod · 0.65
SetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected