From 4ff4f2df65345d21d6f7a86e8b5d16bf7f68247a Mon Sep 17 00:00:00 2001 From: toranger Date: Thu, 28 Feb 2019 14:42:50 +0800 Subject: [PATCH] Check delete object param and fix restore name --- example/object/restore.go | 2 +- object.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/example/object/restore.go b/example/object/restore.go index 7f7388f..984513c 100644 --- a/example/object/restore.go +++ b/example/object/restore.go @@ -34,7 +34,7 @@ func main() { }, } name := "archivetest" - _, err := c.Object.PutRestore(context.Background(), name, opt) + _, err := c.Object.PostRestore(context.Background(), name, opt) if err != nil { panic(err) } diff --git a/object.go b/object.go index 711e418..c311784 100644 --- a/object.go +++ b/object.go @@ -3,6 +3,7 @@ package cos import ( "context" "encoding/xml" + "errors" "fmt" "io" "net/http" @@ -177,6 +178,11 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O // // https://www.qcloud.com/document/product/436/7743 func (s *ObjectService) Delete(ctx context.Context, name string) (*Response, error) { + // When use "" string might call the delete bucket interface + if len(name) == 0 { + return nil, errors.New("empty object name") + } + sendOpt := sendOptions{ baseURL: s.client.BaseURL.BucketURL, uri: "/" + encodeURIComponent(name), @@ -247,7 +253,7 @@ type ObjectRestoreOptions struct { // PutRestore API can recover an object of type archived by COS archive. // // https://cloud.tencent.com/document/product/436/12633 -func (s *ObjectService) PutRestore(ctx context.Context, name string, opt *ObjectRestoreOptions) (*Response, error) { +func (s *ObjectService) PostRestore(ctx context.Context, name string, opt *ObjectRestoreOptions) (*Response, error) { u := fmt.Sprintf("/%s?restore", encodeURIComponent(name)) sendOpt := sendOptions{ baseURL: s.client.BaseURL.BucketURL,