Browse Source

Merge pull request #111 from agin719/cos-v4-dev

Cos v4 dev
master
agin719 4 years ago
committed by GitHub
parent
commit
ea1cccccb1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      cos.go
  2. 1
      example/object/upload.go
  3. 6
      object.go

11
cos.go

@ -22,7 +22,7 @@ import (
const ( const (
// Version current go sdk version // Version current go sdk version
Version = "0.7.21"
Version = "0.7.22"
userAgent = "cos-go-sdk-v5/" + Version userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml" contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com" defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@ -70,6 +70,10 @@ func NewBucketURL(bucketName, region string, secure bool) *url.URL {
return u return u
} }
type Config struct {
EnableCRC bool
}
// Client is a client manages communication with the COS API. // Client is a client manages communication with the COS API.
type Client struct { type Client struct {
client *http.Client client *http.Client
@ -85,6 +89,8 @@ type Client struct {
Object *ObjectService Object *ObjectService
Batch *BatchService Batch *BatchService
CI *CIService CI *CIService
Conf *Config
} }
type service struct { type service struct {
@ -112,6 +118,9 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
client: httpClient, client: httpClient,
UserAgent: userAgent, UserAgent: userAgent,
BaseURL: baseURL, BaseURL: baseURL,
Conf: &Config{
EnableCRC: true,
},
} }
c.common.client = c c.common.client = c
c.Service = (*ServiceService)(&c.common) c.Service = (*ServiceService)(&c.common)

1
example/object/upload.go

@ -51,7 +51,6 @@ func main() {
// Case1 多线程上传对象 // Case1 多线程上传对象
opt := &cos.MultiUploadOptions{ opt := &cos.MultiUploadOptions{
EnableVerification: true,
ThreadPoolSize: 5, ThreadPoolSize: 5,
} }
v, _, err := c.Object.Upload( v, _, err := c.Object.Upload(

6
object.go

@ -746,7 +746,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return nil, nil, err return nil, nil, err
} }
// 校验 // 校验
if opt.EnableVerification {
if s.client.Conf.EnableCRC {
fd, err := os.Open(filepath) fd, err := os.Open(filepath)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -771,7 +771,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
Key: name, Key: name,
ETag: rsp.Header.Get("ETag"), ETag: rsp.Header.Get("ETag"),
} }
if rsp != nil && opt.EnableVerification {
if rsp != nil && s.client.Conf.EnableCRC {
scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma") scoscrc := rsp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64) icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc { if icoscrc != localcrc {
@ -902,7 +902,7 @@ func (s *ObjectService) Upload(ctx context.Context, name string, filepath string
return v, resp, err return v, resp, err
} }
if resp != nil && opt.EnableVerification {
if resp != nil && s.client.Conf.EnableCRC {
scoscrc := resp.Header.Get("x-cos-hash-crc64ecma") scoscrc := resp.Header.Get("x-cos-hash-crc64ecma")
icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64) icoscrc, _ := strconv.ParseUint(scoscrc, 10, 64)
if icoscrc != localcrc { if icoscrc != localcrc {

Loading…
Cancel
Save