
# 获取在线解压策略
#### 功能介绍
桶拥有者或拥有获取在线解压策略权限的用户可通过本接口查询指定桶的文件解压策略。如果策略存在，则返回成功，status code返回值为200。
#### 接口约束
- 您必须是桶拥有者或拥有获取在线解压策略的权限，才能调用本接口，建议使用IAM或桶策略进行授权。了解更多OBS授权方式请参见[OBS不同权限控制方式的区别](https://support.huaweicloud.com/perms-cfg-obs/obs_40_0001.html)。
- OBS支持的Region与Endpoint的对应关系，详细信息请参见[地区与终端节点](https://developer.huaweicloud.com/endpoint?OBS)。
 
#### 方法定义
**func** (obsClient ObsClient) GetBucketDecompression(input \*[GetBucketDecompressionInput], extensions ...extensionOptions) (output \*[GetBucketDecompressionOutput], err error)
#### 请求参数说明
表1请求参数列表 
| **参数名称**   | **参数类型**                                                                             | **是否必选** | **描述**                                                                                                                                                           |
|:---|:---|:---|:---|
| input      | \*[GetBucketDecompressionInput]                      | 必选       | **参数解释：** 获取在线解压策略请求参数，详见[GetBucketDecompressionInput]。                                           |
| 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)。 |
   
 表2GetBucketDecompressionInput 
| **参数名称** | **参数类型** | **是否必选** | **描述**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|:---|
| Bucket   | string   | 必选       | **参数解释** **：** 桶名。 **约束限制：** - 桶命名规则如下： - 需全局唯一，不能与已有的任何桶名称重复，包括其他用户创建的桶。用户删除桶后，立即创建同名桶或并行文件系统会创建失败，需要等待30分钟才能创建。  - 长度范围为3到63个字符，仅支持小写字母、数字、中划线（-）、英文句号（.）。  - 禁止两个英文句号（.）相邻，禁止英文句号（.）和中划线（-）相邻，禁止以英文句号（.）和中划线（-）开头或结尾。  - 禁止使用IP地址。    - 同一用户在同一个区域多次创建同名桶不会报错，创建的桶属性以第一次请求为准。   **默认取值：** 无 |
   
#### 返回结果说明
表3返回结果列表 
| **参数名称** | **参数类型**                                                        | **描述**                                                                                                          |
|:---|:---|:---|
| output   | \*[GetBucketDecompressionOutput] | **参数解释：** 接口返回信息，详见[GetBucketDecompressionOutput]。 |
| err      | error                                                           | **参数解释：** 接口返回错误信息。                                                              |
   
 表4GetBucketDecompressionOutput 
| **参数名称**        | **参数类型**                                                    | **描述**                                                                                                                                                                                                                                                                                                                                                                                |
|:---|:---|:---|
| 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响应头信息。 **默认取值：** 无                                                                                                                                                                                                                          |
| Rules           | \[\][DecompressionRule] | **参数解释：** 在线解压策略。 **取值范围：** 参见[DecompressionRule]。 **默认取值：** 无                                                                                                                           |
   
 表5DecompressionRule 
| **参数名称**       | **参数类型**   | **是否必选** | **描述**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|:---|:---|:---|:---|
| ID             | string     | 必选       | **参数解释：** 解压策略名称。当前桶上配置的解压规则的唯一标识。 **取值范围：** \[1, 256\]，满足"\^\[a-zA-Z0-9_-\]{1, 256}$"，即长度为1\~256个字符。只能由大写或小写的英文字母、数字、下划线（_）和连字符（-）组成。例如：event_0001。 **默认取值：** 无                                                                                                                                      |
| Project        | string     | 必选       | **参数解释：** 项目ID。 **默认取值：** 无                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Agency         | string     | 必选       | **参数解释：** 委托名。客户通过委托赋予OBS服务查询用户桶内指定对象是否存在以及向用户桶内上传对象的权限。 **默认取值：** 无                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Events         | \[\]string | 必选       | **参数解释：** 触发事件类型。 **取值范围：** ``` ["ObjectCreated:*"] ["ObjectCreated:Put"] ["ObjectCreated:Post"] ["ObjectCreated:Copy"] ["ObjectCreated:CompleteMultipartUpload"] ```                                                                                                                                                                                                                                                                                                                                           |
| Prefix         | string     | 可选       | **参数解释：** 匹配规则前缀。 **取值范围：** \[0, 1023\]                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Suffix         | string     | 必选       | **参数解释：** 匹配规则后缀。 **取值范围：** 固定值：.zip                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Overwrite      | int        | 必选       | **参数解释：** 解压后同名文件的处理方式。 **取值范围：** - 0：不覆盖跳过  - 1：不覆盖，以文件的CRC32值重命名  - 2：覆盖。   |
| DecompressPath | string     | 可选       | **参数解释：** 文件解压后存放的路径，不为空时必须以"/"结尾，且不能以"/"开头。 **取值范围：** \[0, 800\]                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| PolicyType     | string     | 必选       | **参数解释：** 文件解压策略类型。 **取值范围：** 固定值：decompress：执行解压操作                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
   
#### 代码示例
本示例用于获取名为examplebucket桶的在线解压策略。
```
package main
import (
    "fmt"
    "os"
)
func main() {
    // 推荐通过环境变量获取AKSK，这里也可以使用其他外部引入方式传入，如果使用硬编码可能会存在泄露风险。
    // 您可以登录访问管理控制台获取访问密钥AK/SK。
    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())
    }
    input := &obs.GetBucketDecompressionInput{}
    // 指定存储桶名称
    input.Bucket = "examplebucket"
    // 获取桶的在线解压策略
    output, err := obsClient.GetBucketDecompression(input)
    if err == nil {
        fmt.Printf("Get bucket(%s)'s decompression policy successful!\n", input.Bucket)
        fmt.Printf("Decompression rules count: %d\n", len(output.Rules))
        for index, rule := range output.Rules {
            fmt.Printf("Rule[%d] - ID: %s, Prefix: %s, Suffix: %s, PolicyType: %s\n",
                index, rule.ID, rule.Prefix, rule.Suffix, rule.PolicyType)
        }
        fmt.Printf("RequestId:%s\n", output.RequestId)
        return
    }
    fmt.Printf("Get bucket(%s)'s decompression policy fail!\n", input.Bucket)
    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_0149.html)。
- 获取在线解压策略过程中返回的错误码含义、问题原因及处理措施可参考[OBS错误码](https://support.huaweicloud.com/api-obs/obs_04_0115.html#section1)。
- 获取在线解压策略相关问题请参见[在线解压](https://support.huaweicloud.com/usermanual-obs/obs_03_0368.html)。
 
