桶配额
更新时间: 2019-03-14 10:05
设置桶配额
您可以通过ObsClient.SetBucketQuota设置桶配额。以下代码展示如何设置桶配额:
- // 引入依赖包
- import (
- "fmt"
- "obs"
- )
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- input := &obs.SetBucketQuotaInput{}
- input.Bucket = "bucketname"
- // 设置桶配额为100MB
- input.Quota = 100 * 1024 * 1024
- output, err := obsClient.SetBucketQuota(input)
- if err == nil {
- fmt.Printf("RequestId:%s\n", output.RequestId)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
说明:
桶配额值必须为非负整数,单位为字节,支持的最大值为263 - 1。
获取桶配额
您可以通过ObsClient.GetBucketQuota获取桶配额。以下代码展示如何获取桶配额:
- // 引入依赖包
- import (
- "fmt"
- "obs"
- )
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- output, err := obsClient.GetBucketQuota("bucketname")
- if err == nil {
- fmt.Printf("Quota:%d\n", output.Quota)
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:管理桶