Browse Source

Merge pull request #75 from maxming2333/master

feat: Object.Delete 增加 optHeader 传递
tags/v0.7.5
agin719 5 years ago
committed by GitHub
parent
commit
ded65e43b6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      example/object/delete.go
  2. 15
      object.go

2
example/object/delete.go

@ -29,7 +29,7 @@ func main() {
name := "test/objectPut.go" name := "test/objectPut.go"
_, err := c.Object.Delete(context.Background(), name)
_, err := c.Object.Delete(context.Background(), name, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }

15
object.go

@ -272,19 +272,32 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
return &res, resp, err return &res, resp, err
} }
type ObjectDeleteOptions struct {
// SSE-C
XCosSSECustomerAglo string `header:"x-cos-server-side-encryption-customer-algorithm,omitempty" url:"-" xml:"-"`
XCosSSECustomerKey string `header:"x-cos-server-side-encryption-customer-key,omitempty" url:"-" xml:"-"`
XCosSSECustomerKeyMD5 string `header:"x-cos-server-side-encryption-customer-key-MD5,omitempty" url:"-" xml:"-"`
//兼容其他自定义头部
XOptionHeader *http.Header `header:"-,omitempty" url:"-" xml:"-"`
}
// Delete Object请求可以将一个文件(Object)删除。 // Delete Object请求可以将一个文件(Object)删除。
// //
// https://www.qcloud.com/document/product/436/7743 // https://www.qcloud.com/document/product/436/7743
func (s *ObjectService) Delete(ctx context.Context, name string) (*Response, error) {
func (s *ObjectService) Delete(ctx context.Context, name string, opt ...*ObjectDeleteOptions) (*Response, error) {
var optHeader *ObjectDeleteOptions
// When use "" string might call the delete bucket interface // When use "" string might call the delete bucket interface
if len(name) == 0 { if len(name) == 0 {
return nil, errors.New("empty object name") return nil, errors.New("empty object name")
} }
if len(opt) > 0 {
optHeader = opt[0]
}
sendOpt := sendOptions{ sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL, baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name), uri: "/" + encodeURIComponent(name),
method: http.MethodDelete, method: http.MethodDelete,
optHeader: optHeader,
} }
resp, err := s.client.send(ctx, &sendOpt) resp, err := s.client.send(ctx, &sendOpt)
return resp, err return resp, err

Loading…
Cancel
Save