
# 获取桶配额(Go SDK)
#### 功能说明
桶配额是桶容量的上限值。调用获取桶配额接口，可获取指定桶的配额值。桶配额为0代表桶容量没有上限。
#### 接口约束
- 桶配额值必须为非负整数，单位为字节，支持的最大值为2^63^-1。
- 桶的拥有者的状态是欠费冻结状态时不可以查询桶配额信息。
- 您必须是桶拥有者或拥有获取桶配额的权限，才能获取桶配额。建议使用IAM或桶策略进行授权，如果使用IAM则需授予obs:bucket:GetBucketQuota权限，如果使用桶策略则需授予GetBucketQuota权限。相关授权方式介绍可参见[OBS权限控制概述](https://support.huaweicloud.com/perms-cfg-obs/obs_40_0001.html)，配置方式详见[使用IAM自定义策略](https://support.huaweicloud.com/usermanual-obs/obs_03_0121.html)、[自定义创建桶策略](https://support.huaweicloud.com/usermanual-obs/obs_03_0123.html)。
- OBS支持的Region与Endpoint的对应关系，详细信息请参见[地区与终端节点](https://developer.huaweicloud.com/endpoint?OBS)。
 
#### 方法定义
**func** (obsClient ObsClient) GetBucketQuota([bucketName] string, extensions...extensionOptions) (output \*[GetBucketQuotaOutput](https://support.huaweicloud.com/sdk-go-devg-obs/obs_33_0413.html), err error)
#### 请求参数说明
 表1请求参数列表 
| **参数名称**   | **参数类型**                                                                             | **是否必选** | **描述**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|:---|:---|:---|:---|
| bucketName | string                                                                               | 必选       | **参数解释** **：** 桶名。 **约束限制：** - 桶命名规则如下： - 需全局唯一，不能与已有的任何桶名称重复，包括其他用户创建的桶。用户删除桶后，立即创建同名桶或并行文件系统会创建失败，需要等待30分钟才能创建。  - 长度范围为3到63个字符，仅支持小写字母、数字、中划线（-）、英文句号（.）。  - 禁止两个英文句号（.）相邻，禁止英文句号（.）和中划线（-）相邻，禁止以英文句号（.）和中划线（-）开头或结尾。  - 禁止使用IP地址。    - 同一用户在同一个区域多次创建同名桶不会报错，创建的桶属性以第一次请求为准。   **默认取值**： 无 |
| extensions | [extensionOptions](https://support.huaweicloud.com/sdk-go-devg-obs/obs_33_0105.html) | 可选       | **参数解释：** 桶相关扩展信息。通过调用拓展配置项为对应请求配置额外的拓展请求头，详情参考[extensionOptions](https://support.huaweicloud.com/sdk-go-devg-obs/obs_33_0105.html)。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
   
#### 返回结果说明
表2返回结果列表 
| **参数名称** | **参数类型**                                                                                   | **描述**                                                                                                    |
|:---|:---|:---|
| output   | \*[GetBucketQuotaOutput](https://support.huaweicloud.com/sdk-go-devg-obs/obs_33_0413.html) | **参数解释：** 接口返回信息，详情参考[GetBucketQuotaOutput]。 |
| err      | error                                                                                      | **参数解释：** 接口返回错误信息。                                                          |
   
 表3GetBucketQuotaOutput 
| **参数名称**        | **参数类型**                | **描述**                                                                                                                                                                                                                                                                                                                                                                               |
|:---|:---|:---|
| StatusCode      | int                     | **参数解释：** HTTP状态码。 **取值范围：** 状态码是一组从2xx（成功）到4xx或5xx（错误）的数字代码，状态码表示了请求响应的状态。完整的状态码列表请参见[状态码](https://support.huaweicloud.com/api-obs/obs_04_0114.html)。 **默认取值：** 无 |
| RequestId       | string                  | **参数解释：** OBS服务端返回的请求ID。 **默认取值：** 无                                                                                                                                                                                                                                                          |
| ResponseHeaders | map\[string\]\[\]string | **参数解释：** HTTP响应头信息。 **默认取值：** 无                                                                                                                                                                                                                                                           |
| Quota           | int64                   | **参数解释：** 桶的配额值。 **取值范围：** 0\~（2^63^-1），单位：字节。 **默认取值：** 0，表示没有限制桶配额。                                                                                                                                                           |
   
#### 代码示例
本示例用于获取桶名为examplebucket的桶配额。
```
package main
import (
    "fmt"
    "os"
    obs "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
)
func main() {
    //推荐通过环境变量获取AKSK，这里也可以使用其他外部引入方式传入，如果使用硬编码可能会存在泄露风险。
    //您可以登录访问管理控制台获取访问密钥AK/SK，获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html。
    ak := os.Getenv("AccessKeyID")
    sk := os.Getenv("SecretAccessKey")
    // 【可选】如果使用临时AK/SK和SecurityToken访问OBS，同样建议您尽量避免使用硬编码，以降低信息泄露风险。您可以通过环境变量获取访问密钥AK/SK，也可以使用其他外部引入方式传入。
    // securityToken := os.Getenv("SecurityToken")
    // endpoint填写Bucket对应的Endpoint，这里以华北-北京四为例，其他地区请按实际情况填写。
    endPoint := "https://obs.cn-north-4.myhuaweicloud.com"
    // 创建obsClient实例
    // 如果使用临时AKSK和SecurityToken访问OBS，需要在创建实例时通过obs.WithSecurityToken方法指定securityToken值。
    obsClient, err := obs.New(ak, sk, endPoint/*, obs.WithSecurityToken(securityToken)*/)
    if err != nil {
        fmt.Printf("Create obsClient error, errMsg: %s", err.Error())
    }
    // 指定存储桶名称
    bucketname := "examplebucket"
    // 获取桶配额
    output, err := obsClient.GetBucketQuota(bucketname)
    if err == nil {
        fmt.Printf("Get bucket(%s)'s quota successful!\n", bucketname)
        fmt.Printf("RequestId:%s\n", output.RequestId)
        fmt.Printf("Quota:%d\n", output.Quota)
        return
    }
    fmt.Printf("Get bucket(%s)'s quota fail!\n", bucketname)
    if obsError, ok := err.(obs.ObsError); ok {
        fmt.Println("An ObsError was found, which means your request sent to OBS was rejected with an error response.")
        fmt.Println(obsError.Error())
    } else {
        fmt.Println("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network.")
        fmt.Println(err)
    }
}
```
#### 相关链接
- 关于获取桶配额的API说明，请参见[获取桶配额](https://support.huaweicloud.com/api-obs/obs_04_0053.html)。
- 更多关于获取桶配额的示例代码，请参见[Github示例](https://github.com/huaweicloud/huaweicloud-sdk-go-obs/blob/master/examples/bucket_operations_sample.go)。
- 获取桶配额过程中返回的错误码含义、问题原因及处理措施可参考[OBS错误码](https://support.huaweicloud.com/api-obs/obs_04_0115.html#section1)。
- 桶和对象相关常见问题请参见[桶和对象相关常见问题](https://support.huaweicloud.com/obs_faq/obs_faq_1200.html)。
 
