# ecloud-sdk-go **Repository Path**: chinamobile_ecloud/ecloud-sdk-go ## Basic Information - **Project Name**: ecloud-sdk-go - **Description**: 移动云OpenAPI平台的Go SDK,可以让Go 开发者无需关心API请求细节即可快速使用弹性云服务器、虚拟私有云等多个移动云服务。 - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-02 - **Last Updated**: 2024-01-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

移动云开发者 GO 软件开发工具包(GO SDK)

欢迎使用移动云Go SDK 。 移动云 Go SDK 让您无需关心请求细节即可快速使用弹性云主机等多个移动云服务。 这里将向您介绍如何获取并使用移动云Go SDK 。 ## 使用前提 - 要使用移动云 Go SDK ,您需要拥有移动云账号以及该账号对应的 Access Key(AK)和 Secret Key(SK)。请在移动云控制台 “我的凭证-访问密钥” 页面上创建和查看您的 AK&SK 。更多信息请查看 [访问密钥](https://ecloud.10086.cn/op-help-center/doc/article/48917) 。 - 移动云 Go SDK 支持 **Go 1.14** 及其以上版本。 ## SDK 获取和安装 移动云支持使用`go get`安装移动云 Go SDK库。 首先,您需要在环境变量中设置GOPROXY及GONOSUMDB,执行如下命令 ```go go env -w GOPROXY=https://ecloud.10086.cn/api/query/developer/nexus/repository/go-sdk/ go env -w GONOSUMDB=gitlab.ecloud.com ``` 其次,您需要安装OpenAPI核心库,获取方式: ```go go get gitlab.ecloud.com/ecloud/ecloudsdkcore ``` 您可以根据需要独立引入SDK依赖包 。以使用云服务器ECS SDK 为例,您需要安装 `ecloudsdkecs` : ``` go go get gitlab.ecloud.com/ecloud/ecloudsdkecs ``` ## 代码示例 - 使用如下代码查看绑定的虚拟网卡列表,首先指定地域(资源池编号)。 - 调用前请根据实际情况替换如下变量: ``、``、`poolId` 。 ``` go // @Title Golang SDK Client // @Description This code is auto generated // @Author Ecloud SDK package main import ( "gitlab.ecloud.com/ecloud/ecloudsdkcore/config" "gitlab.ecloud.com/ecloud/ecloudsdkecs" "gitlab.ecloud.com/ecloud/ecloudsdkecs/model" ) //使用AK&SK初始化账号Client //@param accessKey //@param secretKey //@param poolId //@return Client func createClient(accessKey string, secretKey string, poolId string) *ecloudsdkecs.Client { config := &config.Config{ AccessKey: accessKey, SecretKey: secretKey, PoolId: poolId, } return ecloudsdkecs.NewClient(config) } func main() { client := createClient("", "", "") request := &model.VmGetServerPortsRequest{} response, err := client.VmGetServerPorts(request) } ``` ## 在线调试 [API开放平台](https://ecloud.10086.cn/op-oneapi-static/#/overview) 提供API检索及平台调试,支持全量快速检索、可视化调试、帮助文档查看等能力。 ## 用户手册 * [1. 客户端连接参数](#1-客户端连接参数-top) * [1.1 默认配置](#11-默认配置-top) * [1.2 超时配置](#12-超时配置-top) * [2. 客户端认证信息](#2-客户端认证信息-top) [2.1 使用AK/SK](#2.1-使用AK/SK-top) * [3. 客户端初始化](#3-客户端初始化-top) * [4. 发送请求并查看响应](#4-发送请求并查看响应-top) * [5. 异常处理](#5-异常处理-top) ### 1. 客户端连接参数 #### 1.1 默认配置 ``` go config := &config.Config{ AccessKey: accessKey, SecretKey: secretKey, PoolId: poolId, } ecloudsdkecs.NewClient(config) ``` #### 1.2 超时配置 ``` go config := &config.Config{ AccessKey: accessKey, SecretKey: secretKey, PoolId: poolId, ConnectTimeout: 2, ReadTimeOut: 5, } ``` ### 2. 客户端认证信息 **认证参数说明**: - `ak` - 移动云账号 Access Key - `sk` - 移动云账号 Secret Key - `poolId` - 服务部署区域(资源池编号) #### 2.1 使用 AK 和 SK ``` go config := &config.Config{ AccessKey: accessKey, SecretKey: secretKey, PoolId: poolId, } ``` ### 3. 客户端初始化 ``` go //使用AK&SK初始化账号Client //@param accessKey //@param secretKey //@param poolId //@return Client func createClient(accessKey string, secretKey string, poolId string) *ecloudsdkecs.Client { config := &config.Config{ AccessKey: accessKey, SecretKey: secretKey, PoolId: poolId, } return ecloudsdkecs.NewClient(config) } ``` ### 4. 发送请求并查看响应 ``` go client := createClient("", "", "") request := &model.VmGetServerPortsRequest{} response, err := client.VmGetServerPorts(request) ``` ### 5. 异常处理 SDK 对程序执行过程中各类异常以GenericResponseError进行统一收口。 ```go response, err := client.VmGetServerPorts(request) if err == nil { fmt.Printf("%+v\n", response.Body) } else { fmt.Println(err) } ```