Check delete object param and fix restore name

This commit is contained in:
toranger
2019-02-28 14:42:50 +08:00
parent c95bb6143a
commit 4ff4f2df65
2 changed files with 8 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ func main() {
}, },
} }
name := "archivetest" name := "archivetest"
_, err := c.Object.PutRestore(context.Background(), name, opt) _, err := c.Object.PostRestore(context.Background(), name, opt)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@@ -3,6 +3,7 @@ package cos
import ( import (
"context" "context"
"encoding/xml" "encoding/xml"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "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 // 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) (*Response, error) {
// When use "" string might call the delete bucket interface
if len(name) == 0 {
return nil, errors.New("empty object name")
}
sendOpt := sendOptions{ sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL, baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name), uri: "/" + encodeURIComponent(name),
@@ -247,7 +253,7 @@ type ObjectRestoreOptions struct {
// PutRestore API can recover an object of type archived by COS archive. // PutRestore API can recover an object of type archived by COS archive.
// //
// https://cloud.tencent.com/document/product/436/12633 // 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)) u := fmt.Sprintf("/%s?restore", encodeURIComponent(name))
sendOpt := sendOptions{ sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL, baseURL: s.client.BaseURL.BucketURL,