桶配额

更新时间: 2019-03-14 10:05

设置桶配额

您可以通过ObsClient.SetBucketQuota设置桶配额。以下代码展示如何设置桶配额:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. )
  6.  
  7. var ak = "*** Provide your Access Key ***"
  8. var sk = "*** Provide your Secret Key ***"
  9. var endpoint = "https://your-endpoint"
  10.  
  11. // 创建ObsClient结构体
  12. var obsClient, _ = obs.New(ak, sk, endpoint)
  13.  
  14. func main() {
  15. input := &obs.SetBucketQuotaInput{}
  16. input.Bucket = "bucketname"
  17. // 设置桶配额为100MB
  18. input.Quota = 100 * 1024 * 1024
  19. output, err := obsClient.SetBucketQuota(input)
  20. if err == nil {
  21. fmt.Printf("RequestId:%s\n", output.RequestId)
  22. } else if obsError, ok := err.(obs.ObsError); ok {
  23. fmt.Printf("Code:%s\n", obsError.Code)
  24. fmt.Printf("Message:%s\n", obsError.Message)
  25. }
  26. }

桶配额 - 图1 说明:

桶配额值必须为非负整数,单位为字节,支持的最大值为263 - 1。

获取桶配额

您可以通过ObsClient.GetBucketQuota获取桶配额。以下代码展示如何获取桶配额:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. )
  6.  
  7. var ak = "*** Provide your Access Key ***"
  8. var sk = "*** Provide your Secret Key ***"
  9. var endpoint = "https://your-endpoint"
  10.  
  11. // 创建ObsClient结构体
  12. var obsClient, _ = obs.New(ak, sk, endpoint)
  13.  
  14. func main() {
  15. output, err := obsClient.GetBucketQuota("bucketname")
  16. if err == nil {
  17. fmt.Printf("Quota:%d\n", output.Quota)
  18. } else if obsError, ok := err.(obs.ObsError); ok {
  19. fmt.Printf("Code:%s\n", obsError.Code)
  20. fmt.Printf("Message:%s\n", obsError.Message)
  21. }
  22. }

父主题:管理桶