Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.01 KB

create_bucket.md

File metadata and controls

36 lines (26 loc) · 1.01 KB

Create 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)

The bucketService object is used to manipulate the Bucket and can use all Bucket and Object level APIs. Now perform the real creation of the Bucket operation:

if _, err := bucketService.Put(); err == nil {
    fmt.Printf("Your bucket named \"%s\" in zone \"%s\" has been created successfully\n", bucketName, zoneName)
} else {
    fmt.Printf("Bucket creation failed with given message: %s\n", err)
}

bucketService.Put() will create a Bucket in the specified zone.