Skip to content

Commit ea1cccc

Browse files
authored
Merge pull request #111 from agin719/cos-v4-dev
Cos v4 dev
2 parents 13b56ff + e6618d1 commit ea1cccc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

cos.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
// Version current go sdk version
25-
Version = "0.7.21"
25+
Version = "0.7.22"
2626
userAgent = "cos-go-sdk-v5/" + Version
2727
contentTypeXML = "application/xml"
2828
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@@ -70,6 +70,10 @@ func NewBucketURL(bucketName, region string, secure bool) *url.URL {
7070
return u
7171
}
7272

73+
type Config struct {
74+
EnableCRC bool
75+
}
76+
7377
// Client is a client manages communication with the COS API.
7478
type Client struct {
7579
client *http.Client
@@ -85,6 +89,8 @@ type Client struct {
8589
Object *ObjectService
8690
Batch *BatchService
8791
CI *CIService
92+
93+
Conf *Config
8894
}
8995

9096
type service struct {
@@ -112,6 +118,9 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
112118
client: httpClient,
113119
UserAgent: userAgent,
114120
BaseURL: baseURL,
121+
Conf: &Config{
122+
EnableCRC: true,
123+
},
115124
}
116125
c.common.client = c
117126
c.Service = (*ServiceService)(&c.common)

example/object/upload.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ func main() {
5151

5252
// Case1 多线程上传对象
5353
opt := &cos.MultiUploadOptions{
54-
EnableVerification: true,
55-
ThreadPoolSize: 5,
54+
ThreadPoolSize: 5,
5655
}
5756
v, _, err := c.Object.Upload(
5857
context.Background(), "gomulput1G", "./test1G", opt,

object.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
746746
return nil, nil, err
747747
}
748748
// 校验
749-
if opt.EnableVerification {
749+
if s.client.Conf.EnableCRC {
750750
fd, err := os.Open(filepath)
751751
if err != nil {
752752
return nil, nil, err
@@ -771,7 +771,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
771771
Key: name,
772772
ETag: rsp.Header.Get("ETag"),
773773
}
774-
if rsp != nil && opt.EnableVerification {
774+
if rsp != nil && s.client.Conf.EnableCRC {
775775
scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma")
776776
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
777777
if icoscrc != localcrc {
@@ -902,7 +902,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
902902
return v, resp, err
903903
}
904904

905-
if resp != nil && opt.EnableVerification {
905+
if resp != nil && s.client.Conf.EnableCRC {
906906
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
907907
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
908908
if icoscrc != localcrc {

0 commit comments

Comments
 (0)