Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 1.18 KB

delete_bucket.md

File metadata and controls

41 lines (30 loc) · 1.18 KB

Delete a Bucket

Code Snippet

Initialize the Qingstor object with your AccessKeyID and SecretAccessKey.

import (
	"github.com/qingstor/qingstor-sdk-go/v4/config"
	"github.com/qingstor/qingstor-sdk-go/v4/service"
)

var conf, _ = config.New("YOUR-ACCESS-KEY-ID", "YOUR--SECRET-ACCESS-KEY")
var qingStor, _ = service.Init(conf)

Initialize a Bucket object according to the bucket name you set for subsequent creation:

bucketName := "your-bucket-name"
zoneName := "pek3b"
bucketService, _ := qingStor.Bucket(bucketName, zoneName)

After created the object, we need perform the action to delete a Bucket:

	if resp, err := bucketService.Delete(); err != nil {
		fmt.Printf("Delete bucket(name: %s) failed with given error: %s\n", bucketName, err)
	} else {
		fmt.Printf("The status code expected: 204(actually: %d)\n", *resp.StatusCode)
	}

The function that appears in the code above:

  • bucketService.Delete() Deletes a Bucket named your-bucket-name in the pek3b field.

The object that appears in the above code:

  • The resp object is the return value of the bucketService.Delete() method.
  • resp.StatusCode stores the http status code for the api operation.