Giter Site home page Giter Site logo

alibaba-cloud-sdk-go's Introduction

English | 简体中文

Alibaba Cloud SDK for Go

Go codecov FOSSA Status

Alibaba Cloud SDK for Go allows you to access Alibaba Cloud services such as Elastic Compute Service (ECS), Server Load Balancer (SLB), and CloudMonitor. You can access Alibaba Cloud services without the need to handle API related tasks, such as signing and constructing your requests.

This document introduces how to obtain and call Alibaba Cloud SDK for Go.

Troubleshoot

Troubleshoot Provide OpenAPI diagnosis service to help developers locate quickly and provide solutions for developers through RequestID or error message.

Online Demo

Alibaba Cloud OpenAPI Developer Portal provides the ability to call the cloud product OpenAPI online, and dynamically generate SDK Example code and quick retrieval interface, which can significantly reduce the difficulty of using the cloud API.

Requirements

  • It's necessary for you to make sure your system meet the Requirements, such as installing a Go environment which is new than 1.13.x.

Installation

Use go get to install SDK:

go get -u github.com/aliyun/alibaba-cloud-sdk-go/sdk

Quick Examples

Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.

Create Client

package main

import "github.com/aliyun/alibaba-cloud-sdk-go/sdk"

func main() {
  client, err := sdk.NewClientWithAccessKey("REGION_ID", "ACCESS_KEY_ID", "ACCESS_KEY_SECRET")
  if err != nil {
    // Handle exceptions
    panic(err)
  }
}

ROA Request

package main

import "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"

func main() {
  request := requests.NewCommonRequest()        // Make a common request
  request.Method = "GET"                        // Set request method
  request.Product = "CS"                        // Specify product
  request.Domain = "cs.aliyuncs.com"            // Location Service will not be enabled if the host is specified. For example, service with aCertification     type-Bearer Token should be specified
  request.Version = "2015-12-15"                // Specify product version
  request.PathPattern = "/clusters/[ClusterId]" // Specify path rule with ROA-style
  request.Scheme = "https"                      // Set request scheme. Default: http
  request.ApiName = "DescribeCluster"           // Specify product interface
  request.QueryParams["ClusterId"] = "123456"   // Assign values to parameters in the path
  request.QueryParams["RegionId"] = "region_id" // Specify the requested regionId, if not specified, use the client regionId, then default regionId
  request.TransToAcsRequest()                   // Trans commonrequest to acsRequest, which is used by client.
}

RPC Request

package main

import "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"

func main() {
  request := requests.NewCommonRequest()                // Make a common request
  request.Method = "POST"                               // Set request method
  request.Product = "Ecs"                               // Specify product
  request.Domain = "ecs.aliyuncs.com"                   // Location Service will not be enabled if the host is specified. For example, service with a   Certification type-Bearer Token should be specified
  request.Version = "2014-05-26"                        // Specify product version
  request.Scheme = "https"                              // Set request scheme. Default: http
  request.ApiName = "CreateInstance"                    // Specify product interface
  request.QueryParams["InstanceType"] = "ecs.g5.large"  // Assign values to parameters in the path
  request.QueryParams["RegionId"] = "region_id"         // Specify the requested regionId, if not specified, use the client regionId, then default regionId
  request.TransToAcsRequest()                           // Trans commonrequest to acsRequest, which is used by client.
}

Documentation

Issues

Opening an Issue, Issues not conforming to the guidelines may be closed immediately.

Contribution

Please make sure to read the Contributing Guide before making a pull request.

References

License

FOSSA Status

alibaba-cloud-sdk-go's People

Contributors

ailan-gl avatar aliguyong avatar answer1991 avatar cici503 avatar conan425 avatar dependabot[bot] avatar feiybox avatar fossabot avatar h-hg avatar hegar avatar humanhuang avatar jacksontian avatar jerry-yz avatar jxyowen avatar kaisawind avatar kevinpollet avatar lizebang avatar morlay avatar mozillazg avatar newkedison avatar night556 avatar peze avatar qingtang-sdk avatar riverdancegit avatar sagikazarmark avatar sdk-team avatar thinalai avatar wenzuochao avatar xiaozhu36 avatar yndu13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alibaba-cloud-sdk-go's Issues

translation to english missing

hi alibaba team,

thanks for all the open source projects!
i'm e.g. currently in germany and would love to read through the docs :(
could we agree to use english as default language for the future?

english please

cheers maik

Slb create_v_server_group BackendServers type is string, is it right?

Hi,
I have seen in this page: [https://help.aliyun.com/document_detail/35215.html?spm=a2c4g.11186623.6.763.J7b8y5], *BackendServers* is a list ,

BackendServers=[
    {"ServerId":"vm-233","Port":"80","Weight":"100"},
    {"ServerId":"vm-232","Port":"90","Weight":"100"},
    {"ServerId":"vm-231","Port":"70","Weight":"100"}
]

but in this sdk, *BackendServers* is a string[https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/services/slb/create_v_server_group.go#L87], so ,How can i use this method to create v_server_group, could u provide an example?

[Feature Request] API XXXRequest.Invoke(c *sdk.Client) (*XXXResponse, error)

希望能提供如题接口,并且 Request 组合的 *requests.RpcRequest 可以隐藏,方便使用。

type DescribeVpcsRequest struct {
	ResourceOwnerId      int64  `position:"Query" name:"ResourceOwnerId"`
	ResourceOwnerAccount string `position:"Query" name:"ResourceOwnerAccount"`
	VpcId                string `position:"Query" name:"VpcId"`
	OwnerAccount         string `position:"Query" name:"OwnerAccount"`
	Name                 string `position:"Query" name:"Name"`
	PageSize             int    `position:"Query" name:"PageSize"`
	IsDefault            string `position:"Query" name:"IsDefault"`
	OwnerId              int64  `position:"Query" name:"OwnerId"`
	PageNumber           int    `position:"Query" name:"PageNumber"`
}

func (r DescribeVpcsRequest) Invoke(client *sdk.Client) (response *DescribeVpcsResponse, err error) {
	req := struct {
		*requests.RpcRequest
		DescribeVpcsRequest
	}{
		&requests.RpcRequest{},
		r,
	}
	req.InitWithApiInfo("Vpc", "2016-04-28", "DescribeVpcs", "vpc", "")

	resp := struct {
		*responses.BaseResponse
		DescribeVpcsResponse
	}{
		BaseResponse: &responses.BaseResponse{},
	}
	response = &resp.DescribeVpcsResponse

	err = client.DoAction(&req, &resp)
	return
}

(https://github.com/morlay/aliyun-go/blob/master/clients/vpc/describe_vpcs.go#L11-L43)

以方便混合使用

package main

import (
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
	"github.com/morlay/aliyun-go/clients/ecs"
	"github.com/morlay/aliyun-go/clients/vpc"
	"fmt"
)

func main() { 
    // 创建通用 Client 实例
    client, err := sdk.NewClientWithAccessKey(
        "<your-region-id>", 			// 您的可用区ID
        "<your-access-key-id>", 		// 您的 Access Key ID
        "<your-access-key-secret>")		// 您的 Access Key Secret
    if err != nil {
    	// 异常处理
    	panic(err)
    }
    
    {
    	// 创建 ecs API 请求并设置参数
        req := ecs.DescribeInstancesRequest{
            IoOptimized: "true",
        }
        // 请求接口
        response, err := req.Invoke(client)
        if err != nil {
            panic(err)
        }
        fmt.Println(response)
    }
    
    {
       // 创建 vpc API 请求并设置参数
       req := vpc.DescribeVRoutersRequest{}
       // 请求接口
       response, err := req.Invoke(client)
       if err != nil {
           panic(err)
       }
       fmt.Println(response)
    }
}

另外,https://github.com/morlay/aliyun-go 已经迁移使用 官方 sdk.Client 了。
同时发现一些问题。

PutCustomMetric with NewClientWithEcsRamRole returns error 500

Saving custom metrics data with PutCustomMetric using a client with Access Key (NewClientWithAccessKey) works fine, but with a client with ECS Ram Role (NewClientWithEcsRamRole), the following error is received from the server:

StatusCode : 200
Headers:
-> Date : Thu, 01 Mar 2018 16:49:13 GMT
-> Content-Type : application/json; charset=UTF-8
-> Access-Control-Allow-Origin : *
-> Access-Control-Allow-Methods : POST, GET, OPTIONS
-> Access-Control-Allow-Headers : X-Requested-With, X-Sequence, _aop_secret, _aop_signature
-> Access-Control-Max-Age : 172800
-> Vary : Accept-Encoding
-> Server : Jetty(7.2.2.v20101205)
Content:
-> {"Message":"java.lang.NullPointerException\n\tat com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210)\n\tat com.google.common.cache.LocalCache.get(LocalCache.java:3936)\n\tat com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)\n\tat com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)\n\tat com.aliyun.cms.metrichub.sender.RateCache.acquire(RateCache.java:55)\n\tat com.aliyun.cms.metrichub.custommetric.CustomMetricService.acquire(CustomMetricService.java:244)\n\tat com.aliyun.cms.metrichub.web.CustomMetricController.customPopUpload(CustomMetricController.java:125)\n\tat sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)\n\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)\n\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)\n\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:707)\n\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)\n\tat org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:206)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1621)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:541)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:481)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:564)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)\n\tat org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)\n\tat org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)\n\tat java.lang.Thread.run(Thread.java:766)\n","Code":"500"}

Error on calling several APIs: Specified signature nonce was used already

[Description]:

When calling the following APIs:

  • vpc.DescribeVpcs (HostId: vpc.ap-southeast-2.aliyuncs.com)
  • slb.DescribeLoadBalancers (HostId: slb.ap-southeast-3.aliyuncs.com)
  • rds.DescribeDBInstances (HostId: rds.ap-southeast-3.aliyuncs.com)

They return the common error:

SDK.ServerError 400 Bad Request {"Recommend":"https://error-center.aliyun.com/status/search?Keyword=SignatureNonceUsed&source=PopGw","Message":"Specified signature nonce was used already.","RequestId":"4BC02B9F-6E54-4346-9B2C-5B9896F66540","HostId":"rds.ap-southeast-3.aliyuncs.com","Code":"SignatureNonceUsed"}

[Context]:

  1. This error doesn't always occur, just sometimes within lots of requests.
  2. It seems all the errors occured in "ap-southeast-x" pattern regions. (But not sure!)

SIGSEGV when calling Container Service's DescribeClusterDetail

This happens sporadically when calling DescribeClusterDetail during cluster creation:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x246280e]

goroutine 1071 [running]:
github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses.(*BaseResponse).parseFromHttpResponse(0xc4200db000, 0x0, 0x0, 0x0)
	/Users/nandi/go/src/github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/response.go:99 +0x2e
github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses.Unmarshal(0x3d2a520, 0xc4202332e8, 0x0, 0x3a66ba6, 0x4, 0xa, 0xc420b46900)
	/Users/nandi/go/src/github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/response.go:38 +0x45
github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).DoActionWithSigner(0xc420fa2410, 0x3d4dca0, 0xc420ece8c0, 0x3d2a520, 0xc4202332e8, 0x0, 0x0, 0x2475501, 0xc4200db000)
	/Users/nandi/go/src/github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:274 +0x59e
github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).DoAction(0xc420fa2410, 0x3d4dca0, 0xc420ece8c0, 0x3d2a520, 0xc4202332e8, 0xc420b46800, 0x3a7cd3d)
	/Users/nandi/go/src/github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:151 +0x5b
github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/cs.(*Client).DescribeClusterDetail(0xc420fa2410, 0xc420ece8c0, 0x1e13, 0x2, 0x7fffffe00000)
	/Users/nandi/go/src/github.com/banzaicloud/pipeline/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/cs/describe_cluster_detail.go:27 +0x99

Request SDKs of Logging service, messaging service and function compute

  1. SDK of SLS only contains open account operations, please provide a complete SDK in this repo
  2. The current repository doesn't contain any SDK of messaging service MNS, please provide one
  3. The SDK of function compute only distributed in another repo, could you please integrate them into this repo

UUID error

alibaba-cloud-sdk-go/sdk/utils/utils.go: multiple-value uuid.NewV4() in single-value context

Can't change an (expired) STS token inside an OSS client

There is a problem with STS tokens we encounter. Our use case is similar to the one documented here https://www.alibabacloud.com/help/doc-detail/54579.htm?spm=a2c63.p38356.a3.2.173c3461fmtaEf but with Golang instead of Python.

The issue is with accessing the OSS API from Golang code with STS tokens, this is certainly possible, but the STS tokens are expiring, and there is no way to change the tokens inside an existing OSS client, although in the https://github.com/aliyun/alibaba-cloud-sdk-go the tokens are refreshed on-demand.

Are there any plans to change this behavior our this is not the correct way to use the API? Currently, we have to throw away the OSS client every time the token expires, and users of the API have to implement the same pattern at every use case.

Support SDK for OpenSearch

It seems there is no relevent codes in this repo about Ali OpenSearch, so will it be supported in coming days?

关于消息服务以及内容安全服务的支持

刚发现阿里云官方居然出GoLang的SDK了。赞一个

但是我目前发现支持的服务有点少,是否后续有计划支持消息服务以及内容安全呢。

btw 是否可以提交PR,如果可以那么有对应的代码规范之类的么~

SLB 调用DescribeLoadBalancerAttribute 方法

错误信息 json: cannot unmarshal number into Go struct field .ListenerPort of type string
describe_load_balancer_attribute.go 文件

ListenerPorts struct {
ListenerPort []string json:"ListenerPort" xml:"ListenerPort"
} json:"ListenerPorts" xml:"ListenerPorts"

ListenerPort 类型应该是这个整形的数组吧

responses package里fmt的使用会导致调用过程中出现一些非预期的中间结果

package responses

import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
)

func Unmarshal(response AcsResponse, httpResponse *http.Response, format string) (err error) {
err = response.parseFromHttpResponse(httpResponse)
fmt.Println(response.GetHttpContentString())
if err != nil {
return
}
if strings.ToUpper(format) == "JSON" {
err = json.Unmarshal(response.GetHttpContentBytes(), response)
} else if strings.ToUpper(format) == "XML" {
err = xml.Unmarshal(response.GetHttpContentBytes(), response)
}
return
}

斜体标注处,会在调用方法时产生非预期的中间结果输出,请帮忙确认下是否合理,谢谢!

Instance status should be const

I only find instance status definition in integration package. All instance status should located in ecs package. like:

const (
	InstanceStatusCreating = "Creating"
	InstanceStatusPending  = "Pending"
	InstanceStatusRunning  = "Running"
	InstanceStatusStarting = "Starting"

	InstanceStatusStopped  = "Stopped"
	InstanceStatusStopping = "Stopping"
	InstanceStatusDeleted  = "Deleted"
)

Error: SDK.CanNotResolveEndpoint on DescribeRegions

1. Error when calling the API

When calling ecs.Client.DescribeRegions, the following error returned:

[SDK.CanNotResolveEndpoint] Can not resolve endpoint(param = {"Domain":"","Product":"Ecs","RegionId":"cn-qingdao","LocationProduct":"","LocationEndpoint":""}), please check the user guide

And calling codes are as following:

input := aliecs.CreateDescribeRegionsRequest()
output, err := m.GetEcsClient().DescribeRegions(input)

2. What the meanings of the fields

In ecs package, there is the following definition:

type DescribeRegionsRequest struct {
*requests.RpcRequest
ResourceOwnerAccount string position:"Query" name:"ResourceOwnerAccount"
ResourceOwnerId string position:"Query" name:"ResourceOwnerId"
OwnerAccount string position:"Query" name:"OwnerAccount"
OwnerId string position:"Query" name:"OwnerId"
}

Can you help clarifying the meanings and differences of the following 4 fields? (I didn't find any clues from official document: https://help.aliyun.com/document_detail/25609.html.)

  • ResourceOwnerAccount
  • ResourceOwnerId
  • OwnerAccount
  • OwnerId

Thanks!

Error on DescribeSnapshots: failed to unmarshal .SourceDiskSize of type string

When calling cdn.Client.DescribeUserDomains, it got the following error:

json: cannot unmarshal number into Go struct field .SourceDiskSize of type string

And calling codes are as following:

  gInput := ecs.CreateDescribeSnapshotsRequest()
  // TODO: Workaround
  gInput.Domain = "ecs.aliyuncs.com"
  gInput.RegionId = iaasRegion
  gInput.PageSize = utils.FormatInt64(PageSize)
  gInput.PageNumber = utils.FormatInt64(pageNumber)
  gOutput, err := factory.GetEcsClient().DescribeSnapshots(gInput)

Maybe it's owing to definition inconsistency between Go struct and REST API.

Supplementary Info[2017/12/28]:
content of gOutput.GetHttpContentBytes() is:

{
"PageNumber": 1,
"PageSize": 50,
"TotalCount": 1,
"RequestId": "F94FC9F9-B46D-4804-B986-093FB8D36926",
"Snapshots": {
"Snapshot": [
{
"CreationTime": "2017-11-08T03:58:14Z",
"Description": "",
"Encrypted": false,
"ProductCode": "",
"Progress": "100%",
"SnapshotId": "s-m5eacq02ar6zb64oic40",
"SnapshotName": "snp-test-20171108",
"SourceDiskId": "d-m5efbha9mr8doraejejb",
"SourceDiskSize": 40,
"SourceDiskType": "system",
"SourceStorageType": "disk",
"Status": "accomplished",
"Tags": {
"Tag": [
]
},
"Usage": "none"
}
]
}
}

And it can be found that this issue is caused by wrong data type of "SourceDiskSize". And to change its data type as int (not int64), this issue will be fixed.

云解析ERR:CanNotResolveEndpoint, InvalidVersion

调用云解析的时候,在公司内网测试ok,放到公网服务器(下沙三线、杭州阿里云)上调用接口报错:

[SDK.CanNotResolveEndpoint] Can not resolve endpoint(param = {"Domain":"","Product":"Alidns","RegionId":"cn-hangzhou","LocationProduct":"","LocationEndpointType":""}), please check the user guide

然后参考上述文档,添加设置request.Domain = "ecs.aliyuncs.com"后报InvalidVersion错:

ErrorCode: InvalidVersion
Recommend: https://error-center.aliyun.com/status/search?Keyword=InvalidVersion&source=PopGw
RequestId: 4DC45609-C519-47EC-9E6F-702D74D6499B
Message: Specified parameter Version is not valid.

付费域名解析和非付费域名解析都试过了,都不行。

怎么解决?

sdk does not support windows

When use this sdk to create alicloud resource, there is a following bug:

panic: open /usr/local/go\lib\time\zoneinfo.zip: The system cannot find the path specified.

and after check /usr/local/go/src/time/zoneinfo.go , line 273-278 have the following annotation:

// The time zone database needed by LoadLocation may not be
// present on all systems, especially non-Unix systems.
// LoadLocation looks in the directory or uncompressed zip file
// named by the ZONEINFO environment variable, if any, then looks in
// known installation locations on Unix systems,
// and finally looks in $GOROOT/lib/time/zoneinfo.zip.

Could the issue be fixed?

SDK.JsonUnmarshalError during Container Service DeleteCluster() call

ERRO[2018-08-21T09:18:01+02:00] DeleteClusterResponse: &cs.DeleteClusterResponse{BaseResponse:(*responses.BaseResponse)(0xc420c0eb40)}
  function=DeleteCluster
ERRO[2018-08-21T09:18:01+02:00] Error during delete cluster: [SDK.JsonUnmarshalError] Failed to unmarshal response, but you can get the data via response.GetHttpStatusCode() and response.GetHttpContentString()
caused by:
skipObjectDecoder: expect object or null, error found in #0 byte of ...||..., bigger context ...||...  function=postDeleteCluster

Paginate parameter should be common parameter

I must use some code like follow to complete the paginate api call.

request.PageSize = requests.NewInteger(100)
resp, err = client.DescribeRequest(request)

for {

	if resp.PageNumber*resp.PageSize >= resp.TotalCount {
		break
	}

       request.PageNumber = requests.NewInteger(resp.PageNumber + 1)
       request.PageSize = requests.NewInteger(resp.PageSize)
       //  ...
}

Something very odd.

  1. Why I should use a string as PageNumber ? It shout be a integer !

  2. I must to calculate if there exist next page manually.

I think you can find a more elegant code design from the community sdk.

ecs.DescribeInstances 返回值 CreationTime 时间格式不正确

问题描述:
首先,调用 ecs.DescribeInstances;然后,解析其返回值中 Instances.Instance 元素的 CreationTime 属性,会返回如下错误信息:

parsing time "2017-01-17T09:41Z" as "2006-01-02T15:04:05Z07:00": cannot parse "Z" as ":"

问题分析:
应该是返回值 CreationTime 属性的格式不符合默认格式:time.RFC3339("2006-01-02T15:04:05Z07:00")。

glide get not working.

glide get command not working when local go path exists a higher version of "ali cloud sdk" dependency.

For example, there is a higher version of "github.com/satori/go.uuid" in my local go path.
When i execute "glide get" glide will not download this package to vendor directory, then break build shown.

go build编译后的文件在没有go环境的环境执行报错

环境:ubuntu 14.04
直接在装有go环境的环境执行go build产生的文件,可以正常运行,将文件cp到没有go环境的ubuntu 14.04下执行报错:(调用的方法为:RefreshObjectCaches)

panic: [SDK.CanNotResolveEndpoint] Can not resolve endpoint(param = {"Domain":"","Product":"Cdn","RegionId":"cn-hangzhou","LocationProduct":"","LocationEndpointType":""}), please check the user guide

请问该如何解决,谢谢!

Error on DescribeUserDomains: failed to unmarshal DescribeUserDomainsResponse.Domains

When calling cdn.Client.DescribeUserDomains, it got the following error:

json: cannot unmarshal object into Go struct field DescribeUserDomainsResponse.Domains of type []struct { DomainName string "json:"DomainName""; Cname string "json:"Cname""; CdnType string "json:"CdnType""; DomainStatus string "json:"DomainStatus""; GmtCreated string "json:"GmtCreated""; GmtModified string "json:"GmtModified""; Description string "json:"Description""; SourceType string "json:"SourceType""; SslProtocol string "json:"SslProtocol""; ResourceGroupId string "json:"ResourceGroupId""; Sandbox string "json:"Sandbox""; Sources []string "json:"Sources"" }

And calling codes are as following:

  gInput := cdn.CreateDescribeUserDomainsRequest()
  // TODO: Workaround
  gInput.Domain = "cdn.aliyuncs.com"
  gInput.RegionId = iaasRegion
  gInput.PageSize = utils.FormatInt64(PageSize)
  gInput.PageNumber = utils.FormatInt64(pageNumber)
  gOutput, err := factory.GetCdnClient().DescribeUserDomains(gInput)

Maybe it's owing to definition inconsistency between Go struct and REST API.

Supplementary Info[2017/12/28]:
content of gOutput.GetHttpContentBytes() is:

{
"RequestId": "41BEE10D-8C81-4F0B-9076-061B1CABA231",
"PageNumber": 1,
"PageSize": 50,
"TotalCount": 0,
"Domains": {
"PageData": [
]
}
}

It can be found that an extra filed "PageData" shoud be nested in "Domains" field.

KMS Support?

Is there a timeline for KMS support in the SDK?

It would be very helpful for some things we're trying to do.

使用最新master,原来正常的出错

Error json: cannot unmarshal number into Go struct field .CpuCoreCount of type requests.Integer
Error json: cannot unmarshal number into Go struct field .DiscountPrice of type requests.Float

QueryMetricList Dimension Filtering not working

Trying to filter metric datapoints based on Dimension is not working. Even though metrics with dimension key "instanceId" and value "somevalue" do not exists, the API call still returns datapoints of all metrics whatever their instanceId is.

request := cms.CreateQueryMetricListRequest()
request.StartTime = time.Now().UTC().Add(-5 * time.Minute).Format(time.RFC3339)
request.EndTime = time.Now().UTC().Format(time.RFC3339)
request.Period = "60"
request.Dimensions = "{\"instanceId\":\"somevalue\"}"
request.Project = "custom_project_name"
request.Metric = "cpu_usage"
request.Method = "GET"
response, err := client.QueryMetricList(request)

本地可运行,.exe上传至阿里云后出错

package util
import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)

func SendSMS(PhoneNumbers, SignName, TemplateCode, TemplateParam string) error {
client, _ := sdk.NewClientWithAccessKey("cn-shanghai", "xxxx", "yyyy")
request := requests.NewCommonRequest()
request.Domain = "dysmsapi.aliyuncs.com"
request.Version = "2017-05-25"
request.ApiName = "SendSms"
request.QueryParams["PhoneNumbers"] = PhoneNumbers
request.QueryParams["SignName"] = SignName
request.QueryParams["TemplateCode"] = TemplateCode
request.QueryParams["TemplateParam"] = TemplateParam
response, err := client.ProcessCommonRequest(request)
if err != nil {
fmt.Println(err)
return err
} else if r := response.GetHttpContentString(); !strings.Contains(r, "Message":"OK") {
{
err = fmt.Errorf(r)
}
}
return err
}

/////////////////////////////////////
以上是util包中SendSMS代码,main 中调用 util.SendSMS,编译后在本机(windows 10)运行良好,将编译好的.exe文件上传至阿里云的ECS(windows server),出现错误:
////////////////////////////////////
panic: open c:\go\lib\time\zoneinfo.zip: The system cannot find the path specified.

goroutine 23 [running]:
github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils.GetTimeInFormatISO8601(0x7d0980, 0xc04230a030)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/utils.go:57 +0x149
github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth.completeRpcSignParams(0xa71700, 0xc042034120, 0xa6d3e0, 0xc042004028, 0x84b790, 0xb)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/rpc_signature_composer.go:42 +0x1e8
github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth.signRpcRequest(0xa71700, 0xc042034120, 0xa6d3e0, 0xc042004028, 0x84b790, 0xb)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/rpc_signature_composer.go:26 +0x71
github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth.Sign(0xa71700, 0xc042034120, 0xa6d3e0, 0xc042004028, 0x84b790, 0xb, 0x77b99c, 0x8)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signer.go:87 +0x2a2
github.com/aliyun/alibaba-cloud-sdk-go/sdk.buildHttpRequest(0xa71700, 0xc042034120, 0xa6d3e0, 0xc042004028, 0x84b790, 0xb, 0x8, 0x8, 0xc042004030)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:235 +0x8b
github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).DoActionWithSigner(0xc042308000, 0xa71700, 0xc042034120, 0xa6d5c0, 0xc042004038, 0x0, 0x0, 0x1, 0xc0420320c0)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:192 +0x3c4
github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).DoAction(0xc042308000, 0xa71700, 0xc042034120, 0xa6d5c0, 0xc042004038, 0x0, 0xc042304240)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:151 +0x6c
github.com/aliyun/alibaba-cloud-sdk-go/sdk.(*Client).ProcessCommonRequest(0xc042308000, 0xc042034120, 0x84c6e9, 0xd, 0xc0423042f8)
D:/OneDrive/code/gopath/src/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go:341 +0xae
hao/util.SendSMS(0xc042008210, 0xb, 0x84c328, 0xc, 0x84be6c, 0xc, 0xc04200a440, 0x11, 0x11, 0xc042071080)

[Feature Request] 命名嵌套 struct 类型

https://github.com/aliyun/alibaba-cloud-sdk-go/blob/master/services/vpc/describe_vpcs.go#L85
嵌套类型不太方便用户使用的,比如数据的转存映射,不得不写到请求调用的函数中,不利于测试,代码风格也会比较混乱。

建议用 Action 作为前缀,以命名嵌套的 struct 类型,像这样
https://github.com/morlay/aliyun-go/blob/master/clients/vpc/operations.go#L2336

(几日前没注意官方有 go sdk,故从 java-sdk 中抓取生成了一版本 https://github.com/morlay/aliyun-go

另外,为什么 返回的 json 中
VSwitchIds 是 []VSwitchId
NatGatewayIds 是 []NatGatewayIds 而 RouterTableIds 是 []RouterTableIds

windows bug

os type: windows 10
go version: 1.10
代码:

package main

import (
	"fmt"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

func main() {
	// 创建ecsClient实例
	ecsClient, err := ecs.NewClientWithAccessKey(
		"<your-region-id>",         // 地域ID
		"<your-access-key-id>",     // 您的Access Key ID
		"<your-access-key-secret>") // 您的Access Key Secret
	if err != nil {
		// 异常处理
		panic(err)
	}
	// 创建API请求并设置参数
	request := ecs.CreateDescribeInstancesRequest()
	// 等价于 request.PageSize = "10"
	request.PageSize = requests.NewInteger(10)
	// 发起请求并处理异常
	response, err := ecsClient.DescribeInstances(request)
	if err != nil {
		// 异常处理
		panic(err)
	}
	fmt.Println(response)
}

go run main.go

output:
go build github.com/aliyun/alibaba-cloud-sdk-go/services/ecs: D:\Go\pkg\tool\windows_amd64\compile.exe: fork/exec D:\Go\pkg\tool\windows_amd64\compile.exe: The filename or extension is too long.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.