# Go SDK调用示例
本文以调用CSS的查询集群列表（ListClustersDetails）接口为例，介绍华为云Go SDK的使用方法。
#### 前提条件
- 已获取华为云账号对应的Access Key（AK）和Secret Access Key（SK），具体操作请参见[新增访问密钥](https://support.huaweicloud.com/usermanual-ca/ca_05_0003.html#section1)。
- 运行SDK的环境已安装[Go 1.14](https://go.dev/dl/)及以上版本。
 
#### 安装SDK
在命令终端执行以下命令安装华为云Go SDK。以0.1.218版本的Go SDK为例，最新的SDK版本信息可通过[SDK中心](https://console.huaweicloud.com/apiexplorer/#/sdkcenter?language=Go)查看获取。
```
go get github.com/huaweicloud/huaweicloud-sdk-go-v3@v0.1.218
```
#### 使用SDK
以下是一个完整的Go示例，演示如何使用华为云Go SDK调用查询集群列表（ListClustersDetails）接口。
- 如果需要获取其他接口的SDK示例，请参见[获取SDK示例代码](https://support.huaweicloud.com/sdkreference-css/css_11_0002.html)。
- 本示例中仅提供了基本的接口参数配置说明，更多的进阶配置请参见SDK的[用户手册](https://github.com/huaweicloud/huaweicloud-sdk-go-v3/blob/master/README_CN.md#sdk-获取和安装)。
- 如果把认证用的AK/SK直接写到代码中会有较大的安全风险，建议在配置文件或环境变量中以密文存放AK/SK，使用时解密，确保安全。本示例中把AK和SK保存为环境变量CLOUD_SDK_AK和CLOUD_SDK_SK，具体操作请参见[环境变量](https://github.com/huaweicloud/huaweicloud-sdk-go-v3/blob/master/README_CN.md#241-环境变量-top)。
```
package main
import (
"fmt"
"os"        
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
css "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/model"
region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/css/v1/region"
)
func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    auth, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    hcClient, err := css.CssClientBuilder().
         WithRegion(region.ValueOf("cn-north-4")).
         WithCredential(auth).
         SafeBuild()
    if err != nil {
        fmt.Println(err)
        return
    }
    client := css.NewCssClient(hcClient)
    request := &model.ListClustersDetailsRequest{}
response, err := client.ListClustersDetails(request)
if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}
```
