From 48408a60a61c187b7cee631f7f6fa4513820ef60 Mon Sep 17 00:00:00 2001 From: cqc Date: Tue, 11 Jul 2023 17:21:36 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E6=A1=B6=E5=88=A4=E6=96=AD=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/s3/api.go | 15 ++++++++------- test/bucketsample_test.go | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/service/s3/api.go b/service/s3/api.go index 37b323d..120db0a 100755 --- a/service/s3/api.go +++ b/service/s3/api.go @@ -1025,15 +1025,16 @@ func (c *S3) HeadBucket(input *HeadBucketInput) (*HeadBucketOutput, error) { } //判断桶是否存在 -func (c *S3) HeadBucketExist(bucket string) bool { - input := &HeadBucketInput{ +func (c *S3) HeadBucketExist(bucket string) (bool, error) { + var err error + req, _ := c.HeadBucketRequest(&HeadBucketInput{ Bucket: aws.String(bucket), + }) + err = req.Send() + if err == nil && req.HTTPResponse.StatusCode == 200 { + return true, nil } - _, err := c.HeadBucket(input) - if err != nil { - return false - } - return true + return false, err } var opHeadBucket *aws.Operation diff --git a/test/bucketsample_test.go b/test/bucketsample_test.go index 4958bd3..60c3aa9 100644 --- a/test/bucketsample_test.go +++ b/test/bucketsample_test.go @@ -22,11 +22,11 @@ func (s *Ks3utilCommandSuite) TestCreateBucket(c *C) { //判断bucket桶是否存在 func (s *Ks3utilCommandSuite) TestBucketExist(c *C) { - exist := client.HeadBucketExist(bucket) - if exist { + exist, err := client.HeadBucketExist(bucket) + if exist && err == nil { fmt.Println("bucket exist") } else { - fmt.Println("bucket not exist") + fmt.Println(err) } }