Skip to content

Commit

Permalink
[fix] 桶判断示例
Browse files Browse the repository at this point in the history
  • Loading branch information
wilac-pv committed Jul 11, 2023
1 parent f093b17 commit 48408a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions service/s3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/bucketsample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 48408a6

Please sign in to comment.