Skip to content

Commit 2273d4f

Browse files
taowei.wtwkkuai
authored andcommitted
add CreateBucketXml
1 parent bb443e8 commit 2273d4f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

oss/client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ func (client Client) CreateBucket(bucketName string, options ...Option) error {
148148
return CheckRespCode(resp.StatusCode, []int{http.StatusOK})
149149
}
150150

151+
// create bucket xml
152+
func (client Client) CreateBucketXml(bucketName string, xmlBody string, options ...Option) error {
153+
buffer := new(bytes.Buffer)
154+
buffer.Write([]byte(xmlBody))
155+
contentType := http.DetectContentType(buffer.Bytes())
156+
headers := map[string]string{}
157+
headers[HTTPHeaderContentType] = contentType
158+
159+
params := map[string]interface{}{}
160+
resp, err := client.do("PUT", bucketName, params, headers, buffer, options...)
161+
if err != nil {
162+
return err
163+
}
164+
165+
defer resp.Body.Close()
166+
return CheckRespCode(resp.StatusCode, []int{http.StatusOK})
167+
}
168+
151169
// ListBuckets lists buckets of the current account under the given endpoint, with optional filters.
152170
//
153171
// options specifies the filters such as Prefix, Marker and MaxKeys. Prefix is the bucket name's prefix filter.

oss/client_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,3 +4483,26 @@ func (s *OssClientSuite) TestGetBucketCName(c *C) {
44834483
err = client.DeleteBucket(bucketName)
44844484
c.Assert(err, IsNil)
44854485
}
4486+
4487+
func (s *OssClientSuite) TestCreateBucketXml(c *C) {
4488+
client, err := New(endpoint, accessID, accessKey)
4489+
c.Assert(err, IsNil)
4490+
4491+
bucketName := bucketNamePrefix + RandLowStr(5)
4492+
xmlBody := `
4493+
<?xml version="1.0" encoding="UTF-8"?>
4494+
<CreateBucketConfiguration>
4495+
<StorageClass>IA</StorageClass>
4496+
</CreateBucketConfiguration>
4497+
`
4498+
err = client.CreateBucketXml(bucketName,xmlBody)
4499+
c.Assert(err, IsNil)
4500+
4501+
//check
4502+
bucketInfo,_:= client.GetBucketInfo(bucketName)
4503+
c.Assert(bucketInfo.BucketInfo.StorageClass, Equals, "IA")
4504+
err = client.DeleteBucket(bucketName)
4505+
c.Assert(err, IsNil)
4506+
}
4507+
4508+

oss/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ const (
235235

236236
NullVersion = "null"
237237

238-
Version = "v2.1.11" // Go SDK version
238+
Version = "v2.2.0" // Go SDK version
239239
)
240240

241241
// FrameType

0 commit comments

Comments
 (0)