Skip to content

Commit 3f30427

Browse files
author
jojoliang
committed
add BucketArchConfig to PutBucket, update copy error return
1 parent 8659476 commit 3f30427

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

bucket.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ type BucketPutOptions struct {
6262
CreateBucketConfiguration *CreateBucketConfiguration `header:"-" url:"-" xml:"-"`
6363
}
6464
type CreateBucketConfiguration struct {
65-
XMLName xml.Name `xml:"CreateBucketConfiguration"`
66-
BucketAZConfig string `xml:"BucketAZConfig,omitempty"`
65+
XMLName xml.Name `xml:"CreateBucketConfiguration"`
66+
BucketAZConfig string `xml:"BucketAZConfig,omitempty"`
67+
BucketArchConfig string `xml:"BucketArchConfig,omitempty"`
6768
}
6869

6970
// Put Bucket请求可以在指定账号下创建一个Bucket。

cos.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
const (
2626
// Version current go sdk version
27-
Version = "0.7.37"
27+
Version = "0.7.38"
2828
UserAgent = "cos-go-sdk-v5/" + Version
2929
contentTypeXML = "application/xml"
3030
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@@ -316,7 +316,7 @@ func (c *Client) doAPI(ctx context.Context, req *http.Request, result interface{
316316

317317
if result != nil {
318318
if w, ok := result.(io.Writer); ok {
319-
io.Copy(w, resp.Body)
319+
_, err = io.Copy(w, resp.Body)
320320
} else {
321321
err = xml.NewDecoder(resp.Body).Decode(result)
322322
if err == io.EOF {

object.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,21 +406,32 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
406406
}
407407
copyOpt.XCosCopySource = u
408408

409+
var bs bytes.Buffer
409410
sendOpt := sendOptions{
410411
baseURL: s.client.BaseURL.BucketURL,
411412
uri: "/" + encodeURIComponent(name),
412413
method: http.MethodPut,
413414
body: nil,
414415
optHeader: copyOpt,
415-
result: &res,
416+
result: &bs,
416417
}
417418
resp, err := s.client.doRetry(ctx, &sendOpt)
418-
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
419-
if resp != nil && resp.StatusCode == 200 {
420-
if err != nil {
421-
return &res, resp, fmt.Errorf("response 200 OK, but body contains an error, RequestId: %v, Error: %v", resp.Header.Get("X-Cos-Request-Id"), err)
419+
420+
if err == nil { // 请求正常
421+
err = xml.Unmarshal(bs.Bytes(), &res) // body 正常返回
422+
if err == io.EOF {
423+
err = nil
424+
}
425+
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
426+
if resp != nil && resp.StatusCode == 200 {
427+
if err != nil {
428+
resErr := &ErrorResponse{Response: resp.Response}
429+
xml.Unmarshal(bs.Bytes(), resErr)
430+
return &res, resp, resErr
431+
}
422432
}
423433
}
434+
424435
return &res, resp, err
425436
}
426437

object_part.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cos
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/xml"
67
"errors"
@@ -271,20 +272,31 @@ func (s *ObjectService) CopyPart(ctx context.Context, name, uploadID string, par
271272
opt.XCosCopySource = sourceURL
272273
u := fmt.Sprintf("/%s?partNumber=%d&uploadId=%s", encodeURIComponent(name), partNumber, uploadID)
273274
var res CopyPartResult
275+
var bs bytes.Buffer
274276
sendOpt := sendOptions{
275277
baseURL: s.client.BaseURL.BucketURL,
276278
uri: u,
277279
method: http.MethodPut,
278280
optHeader: opt,
279-
result: &res,
281+
result: &bs,
280282
}
281283
resp, err := s.client.send(ctx, &sendOpt)
282-
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
283-
if resp != nil && resp.StatusCode == 200 {
284-
if err != nil {
285-
return &res, resp, fmt.Errorf("response 200 OK, but body contains an error, RequestId: %v, Error: %v", resp.Header.Get("X-Cos-Request-Id"), err)
284+
285+
if err == nil { // 请求正常
286+
err = xml.Unmarshal(bs.Bytes(), &res) // body 正常返回
287+
if err == io.EOF {
288+
err = nil
289+
}
290+
// If the error occurs during the copy operation, the error response is embedded in the 200 OK response. This means that a 200 OK response can contain either a success or an error.
291+
if resp != nil && resp.StatusCode == 200 {
292+
if err != nil {
293+
resErr := &ErrorResponse{Response: resp.Response}
294+
xml.Unmarshal(bs.Bytes(), resErr)
295+
return &res, resp, resErr
296+
}
286297
}
287298
}
299+
288300
return &res, resp, err
289301
}
290302

0 commit comments

Comments
 (0)