diff --git a/golang/ChangeLog.txt b/golang/ChangeLog.txt index e052a6a..e7786ef 100644 --- a/golang/ChangeLog.txt +++ b/golang/ChangeLog.txt @@ -1,3 +1,6 @@ +2023-03-18 Version: v3.0.0 +- v3.x + 2023-02-07 Version: v2.0.3 - Add ca configs. - Get accessDeniedDetail from error map. diff --git a/golang/client/client.go b/golang/client/client.go index c747919..9e97fbe 100644 --- a/golang/client/client.go +++ b/golang/client/client.go @@ -1,365 +1,18 @@ // This file is auto-generated, don't edit it. Thanks. -/** - * This is for OpenApi SDK - */ +// Description: +// +// This is for OpenApi SDK package client import ( spi "github.com/alibabacloud-go/alibabacloud-gateway-spi/client" - openapiutil "github.com/alibabacloud-go/openapi-util/service" + openapiutil "github.com/alibabacloud-go/openapi-util/v2/service" util "github.com/alibabacloud-go/tea-utils/v2/service" xml "github.com/alibabacloud-go/tea-xml/service" - "github.com/alibabacloud-go/tea/tea" + "github.com/alibabacloud-go/tea/v2/tea" credential "github.com/aliyun/credentials-go/credentials" - "io" ) -type GlobalParameters struct { - Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` - Queries map[string]*string `json:"queries,omitempty" xml:"queries,omitempty"` -} - -func (s GlobalParameters) String() string { - return tea.Prettify(s) -} - -func (s GlobalParameters) GoString() string { - return s.String() -} - -func (s *GlobalParameters) SetHeaders(v map[string]*string) *GlobalParameters { - s.Headers = v - return s -} - -func (s *GlobalParameters) SetQueries(v map[string]*string) *GlobalParameters { - s.Queries = v - return s -} - -/** - * Model for initing client - */ -type Config struct { - // accesskey id - AccessKeyId *string `json:"accessKeyId,omitempty" xml:"accessKeyId,omitempty"` - // accesskey secret - AccessKeySecret *string `json:"accessKeySecret,omitempty" xml:"accessKeySecret,omitempty"` - // security token - SecurityToken *string `json:"securityToken,omitempty" xml:"securityToken,omitempty"` - // http protocol - Protocol *string `json:"protocol,omitempty" xml:"protocol,omitempty"` - // http method - Method *string `json:"method,omitempty" xml:"method,omitempty"` - // region id - RegionId *string `json:"regionId,omitempty" xml:"regionId,omitempty"` - // read timeout - ReadTimeout *int `json:"readTimeout,omitempty" xml:"readTimeout,omitempty"` - // connect timeout - ConnectTimeout *int `json:"connectTimeout,omitempty" xml:"connectTimeout,omitempty"` - // http proxy - HttpProxy *string `json:"httpProxy,omitempty" xml:"httpProxy,omitempty"` - // https proxy - HttpsProxy *string `json:"httpsProxy,omitempty" xml:"httpsProxy,omitempty"` - // credential - Credential credential.Credential `json:"credential,omitempty" xml:"credential,omitempty"` - // endpoint - Endpoint *string `json:"endpoint,omitempty" xml:"endpoint,omitempty"` - // proxy white list - NoProxy *string `json:"noProxy,omitempty" xml:"noProxy,omitempty"` - // max idle conns - MaxIdleConns *int `json:"maxIdleConns,omitempty" xml:"maxIdleConns,omitempty"` - // network for endpoint - Network *string `json:"network,omitempty" xml:"network,omitempty"` - // user agent - UserAgent *string `json:"userAgent,omitempty" xml:"userAgent,omitempty"` - // suffix for endpoint - Suffix *string `json:"suffix,omitempty" xml:"suffix,omitempty"` - // socks5 proxy - Socks5Proxy *string `json:"socks5Proxy,omitempty" xml:"socks5Proxy,omitempty"` - // socks5 network - Socks5NetWork *string `json:"socks5NetWork,omitempty" xml:"socks5NetWork,omitempty"` - // endpoint type - EndpointType *string `json:"endpointType,omitempty" xml:"endpointType,omitempty"` - // OpenPlatform endpoint - OpenPlatformEndpoint *string `json:"openPlatformEndpoint,omitempty" xml:"openPlatformEndpoint,omitempty"` - // Deprecated - // credential type - Type *string `json:"type,omitempty" xml:"type,omitempty"` - // Signature Version - SignatureVersion *string `json:"signatureVersion,omitempty" xml:"signatureVersion,omitempty"` - // Signature Algorithm - SignatureAlgorithm *string `json:"signatureAlgorithm,omitempty" xml:"signatureAlgorithm,omitempty"` - // Global Parameters - GlobalParameters *GlobalParameters `json:"globalParameters,omitempty" xml:"globalParameters,omitempty"` - // privite key for client certificate - Key *string `json:"key,omitempty" xml:"key,omitempty"` - // client certificate - Cert *string `json:"cert,omitempty" xml:"cert,omitempty"` - // server certificate - Ca *string `json:"ca,omitempty" xml:"ca,omitempty"` -} - -func (s Config) String() string { - return tea.Prettify(s) -} - -func (s Config) GoString() string { - return s.String() -} - -func (s *Config) SetAccessKeyId(v string) *Config { - s.AccessKeyId = &v - return s -} - -func (s *Config) SetAccessKeySecret(v string) *Config { - s.AccessKeySecret = &v - return s -} - -func (s *Config) SetSecurityToken(v string) *Config { - s.SecurityToken = &v - return s -} - -func (s *Config) SetProtocol(v string) *Config { - s.Protocol = &v - return s -} - -func (s *Config) SetMethod(v string) *Config { - s.Method = &v - return s -} - -func (s *Config) SetRegionId(v string) *Config { - s.RegionId = &v - return s -} - -func (s *Config) SetReadTimeout(v int) *Config { - s.ReadTimeout = &v - return s -} - -func (s *Config) SetConnectTimeout(v int) *Config { - s.ConnectTimeout = &v - return s -} - -func (s *Config) SetHttpProxy(v string) *Config { - s.HttpProxy = &v - return s -} - -func (s *Config) SetHttpsProxy(v string) *Config { - s.HttpsProxy = &v - return s -} - -func (s *Config) SetCredential(v credential.Credential) *Config { - s.Credential = v - return s -} - -func (s *Config) SetEndpoint(v string) *Config { - s.Endpoint = &v - return s -} - -func (s *Config) SetNoProxy(v string) *Config { - s.NoProxy = &v - return s -} - -func (s *Config) SetMaxIdleConns(v int) *Config { - s.MaxIdleConns = &v - return s -} - -func (s *Config) SetNetwork(v string) *Config { - s.Network = &v - return s -} - -func (s *Config) SetUserAgent(v string) *Config { - s.UserAgent = &v - return s -} - -func (s *Config) SetSuffix(v string) *Config { - s.Suffix = &v - return s -} - -func (s *Config) SetSocks5Proxy(v string) *Config { - s.Socks5Proxy = &v - return s -} - -func (s *Config) SetSocks5NetWork(v string) *Config { - s.Socks5NetWork = &v - return s -} - -func (s *Config) SetEndpointType(v string) *Config { - s.EndpointType = &v - return s -} - -func (s *Config) SetOpenPlatformEndpoint(v string) *Config { - s.OpenPlatformEndpoint = &v - return s -} - -func (s *Config) SetType(v string) *Config { - s.Type = &v - return s -} - -func (s *Config) SetSignatureVersion(v string) *Config { - s.SignatureVersion = &v - return s -} - -func (s *Config) SetSignatureAlgorithm(v string) *Config { - s.SignatureAlgorithm = &v - return s -} - -func (s *Config) SetGlobalParameters(v *GlobalParameters) *Config { - s.GlobalParameters = v - return s -} - -func (s *Config) SetKey(v string) *Config { - s.Key = &v - return s -} - -func (s *Config) SetCert(v string) *Config { - s.Cert = &v - return s -} - -func (s *Config) SetCa(v string) *Config { - s.Ca = &v - return s -} - -type OpenApiRequest struct { - Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` - Query map[string]*string `json:"query,omitempty" xml:"query,omitempty"` - Body interface{} `json:"body,omitempty" xml:"body,omitempty"` - Stream io.Reader `json:"stream,omitempty" xml:"stream,omitempty"` - HostMap map[string]*string `json:"hostMap,omitempty" xml:"hostMap,omitempty"` - EndpointOverride *string `json:"endpointOverride,omitempty" xml:"endpointOverride,omitempty"` -} - -func (s OpenApiRequest) String() string { - return tea.Prettify(s) -} - -func (s OpenApiRequest) GoString() string { - return s.String() -} - -func (s *OpenApiRequest) SetHeaders(v map[string]*string) *OpenApiRequest { - s.Headers = v - return s -} - -func (s *OpenApiRequest) SetQuery(v map[string]*string) *OpenApiRequest { - s.Query = v - return s -} - -func (s *OpenApiRequest) SetBody(v interface{}) *OpenApiRequest { - s.Body = v - return s -} - -func (s *OpenApiRequest) SetStream(v io.Reader) *OpenApiRequest { - s.Stream = v - return s -} - -func (s *OpenApiRequest) SetHostMap(v map[string]*string) *OpenApiRequest { - s.HostMap = v - return s -} - -func (s *OpenApiRequest) SetEndpointOverride(v string) *OpenApiRequest { - s.EndpointOverride = &v - return s -} - -type Params struct { - Action *string `json:"action,omitempty" xml:"action,omitempty" require:"true"` - Version *string `json:"version,omitempty" xml:"version,omitempty" require:"true"` - Protocol *string `json:"protocol,omitempty" xml:"protocol,omitempty" require:"true"` - Pathname *string `json:"pathname,omitempty" xml:"pathname,omitempty" require:"true"` - Method *string `json:"method,omitempty" xml:"method,omitempty" require:"true"` - AuthType *string `json:"authType,omitempty" xml:"authType,omitempty" require:"true"` - BodyType *string `json:"bodyType,omitempty" xml:"bodyType,omitempty" require:"true"` - ReqBodyType *string `json:"reqBodyType,omitempty" xml:"reqBodyType,omitempty" require:"true"` - Style *string `json:"style,omitempty" xml:"style,omitempty"` -} - -func (s Params) String() string { - return tea.Prettify(s) -} - -func (s Params) GoString() string { - return s.String() -} - -func (s *Params) SetAction(v string) *Params { - s.Action = &v - return s -} - -func (s *Params) SetVersion(v string) *Params { - s.Version = &v - return s -} - -func (s *Params) SetProtocol(v string) *Params { - s.Protocol = &v - return s -} - -func (s *Params) SetPathname(v string) *Params { - s.Pathname = &v - return s -} - -func (s *Params) SetMethod(v string) *Params { - s.Method = &v - return s -} - -func (s *Params) SetAuthType(v string) *Params { - s.AuthType = &v - return s -} - -func (s *Params) SetBodyType(v string) *Params { - s.BodyType = &v - return s -} - -func (s *Params) SetReqBodyType(v string) *Params { - s.ReqBodyType = &v - return s -} - -func (s *Params) SetStyle(v string) *Params { - s.Style = &v - return s -} - type Client struct { Endpoint *string RegionId *string @@ -390,12 +43,15 @@ type Client struct { Key *string Cert *string Ca *string + DisableHttp2 *bool + RetryOptions *tea.RetryOptions } -/** - * Init client with Config - * @param config config contains the necessary information to create a client - */ +// Description: +// +// Init client with Config +// +// @param config - config contains the necessary information to create a client func NewClient(config *Config) (*Client, error) { client := new(Client) err := client.Init(config) @@ -404,10 +60,10 @@ func NewClient(config *Config) (*Client, error) { func (client *Client) Init(config *Config) (_err error) { if tea.BoolValue(util.IsUnset(config)) { - _err = tea.NewSDKError(map[string]interface{}{ - "code": "ParameterMissing", - "message": "'config' can not be unset", - }) + _err = &ClientError{ + Code: tea.String("ParameterMissing"), + Message: tea.String("'config' can not be unset"), + } return _err } @@ -455,21 +111,32 @@ func (client *Client) Init(config *Config) (_err error) { client.Key = config.Key client.Cert = config.Cert client.Ca = config.Ca + client.DisableHttp2 = config.DisableHttp2 + client.RetryOptions = config.RetryOptions return nil } -/** - * Encapsulate the request and invoke the network - * @param action api name - * @param version product version - * @param protocol http or https - * @param method e.g. GET - * @param authType authorization type e.g. AK - * @param bodyType response body type e.g. String - * @param request object of OpenApiRequest - * @param runtime which controls some details of call api, such as retry times - * @return the response - */ +// Description: +// +// Encapsulate the request and invoke the network +// +// @param action - api name +// +// @param version - product version +// +// @param protocol - http or https +// +// @param method - e.g. GET +// +// @param authType - authorization type e.g. AK +// +// @param bodyType - response body type e.g. String +// +// @param request - object of OpenApiRequest +// +// @param runtime - which controls some details of call api, such as retry times +// +// @return the response func (client *Client) DoRPCRequest(action *string, version *string, protocol *string, method *string, authType *string, bodyType *string, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { _err = tea.Validate(request) if _err != nil { @@ -479,8 +146,7 @@ func (client *Client) DoRPCRequest(action *string, version *string, protocol *st if _err != nil { return _result, _err } - _runtime := map[string]interface{}{ - "timeouted": "retry", + _runtime := tea.NewRuntimeObject(map[string]interface{}{ "key": tea.StringValue(util.DefaultString(runtime.Key, client.Key)), "cert": tea.StringValue(util.DefaultString(runtime.Cert, client.Cert)), "ca": tea.StringValue(util.DefaultString(runtime.Ca, client.Ca)), @@ -492,28 +158,24 @@ func (client *Client) DoRPCRequest(action *string, version *string, protocol *st "socks5Proxy": tea.StringValue(util.DefaultString(runtime.Socks5Proxy, client.Socks5Proxy)), "socks5NetWork": tea.StringValue(util.DefaultString(runtime.Socks5NetWork, client.Socks5NetWork)), "maxIdleConns": tea.IntValue(util.DefaultNumber(runtime.MaxIdleConns, client.MaxIdleConns)), - "retry": map[string]interface{}{ - "retryable": tea.BoolValue(runtime.Autoretry), - "maxAttempts": tea.IntValue(util.DefaultNumber(runtime.MaxAttempts, tea.Int(3))), - }, - "backoff": map[string]interface{}{ - "policy": tea.StringValue(util.DefaultString(runtime.BackoffPolicy, tea.String("no"))), - "period": tea.IntValue(util.DefaultNumber(runtime.BackoffPeriod, tea.Int(1))), - }, - "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + "retryOptions": client.RetryOptions, + "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + }) + + var retryPolicyContext *tea.RetryPolicyContext + var request_ *tea.Request + var response_ *tea.Response + retriesAttempted := int(0) + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), } - _resp := make(map[string]interface{}) - for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ { - if _retryTimes > 0 { - _backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes)) - if tea.IntValue(_backoffTime) > 0 { - tea.Sleep(_backoffTime) - } - } + for tea.BoolValue(tea.ShouldRetry(_runtime.RetryOptions, retryPolicyContext)) { + _backoffDelayTime := tea.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext) + tea.Sleep(_backoffDelayTime) _resp, _err = func() (map[string]interface{}, error) { - request_ := tea.NewRequest() + request_ = tea.NewRequest() request_.Protocol = util.DefaultString(client.Protocol, protocol) request_.Method = method request_.Pathname = tea.String("/") @@ -626,15 +288,38 @@ func (client *Client) DoRPCRequest(action *string, version *string, protocol *st } requestId := DefaultAny(err["RequestId"], err["requestId"]) - err["statusCode"] = response_.StatusCode - _err = tea.NewSDKError(map[string]interface{}{ - "code": tea.ToString(DefaultAny(err["Code"], err["code"])), - "message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId), - "data": err, - "description": tea.ToString(DefaultAny(err["Description"], err["description"])), - "accessDeniedDetail": DefaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]), - }) - return _result, _err + code := DefaultAny(err["Code"], err["code"]) + if tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.User"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.Api"))) { + _err = &ThrottlingError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RetryAfter: openapiutil.GetThrottlingTimeLeft(response_.Headers), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else if tea.BoolValue(util.Is4xx(response_.StatusCode)) { + _err = &ClientError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + AccessDeniedDetail: client.GetAccessDeniedDetail(err), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else { + _err = &ServerError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } + } if tea.BoolValue(util.EqualString(bodyType, tea.String("binary"))) { @@ -712,27 +397,44 @@ func (client *Client) DoRPCRequest(action *string, version *string, protocol *st } }() - if !tea.BoolValue(tea.Retryable(_err)) { + if _err == nil { break } + retriesAttempted++ + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), + Request: request_, + Response: response_, + Error: _err, + } } return _resp, _err } -/** - * Encapsulate the request and invoke the network - * @param action api name - * @param version product version - * @param protocol http or https - * @param method e.g. GET - * @param authType authorization type e.g. AK - * @param pathname pathname of every api - * @param bodyType response body type e.g. String - * @param request object of OpenApiRequest - * @param runtime which controls some details of call api, such as retry times - * @return the response - */ +// Description: +// +// Encapsulate the request and invoke the network +// +// @param action - api name +// +// @param version - product version +// +// @param protocol - http or https +// +// @param method - e.g. GET +// +// @param authType - authorization type e.g. AK +// +// @param pathname - pathname of every api +// +// @param bodyType - response body type e.g. String +// +// @param request - object of OpenApiRequest +// +// @param runtime - which controls some details of call api, such as retry times +// +// @return the response func (client *Client) DoROARequest(action *string, version *string, protocol *string, method *string, authType *string, pathname *string, bodyType *string, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { _err = tea.Validate(request) if _err != nil { @@ -742,8 +444,7 @@ func (client *Client) DoROARequest(action *string, version *string, protocol *st if _err != nil { return _result, _err } - _runtime := map[string]interface{}{ - "timeouted": "retry", + _runtime := tea.NewRuntimeObject(map[string]interface{}{ "key": tea.StringValue(util.DefaultString(runtime.Key, client.Key)), "cert": tea.StringValue(util.DefaultString(runtime.Cert, client.Cert)), "ca": tea.StringValue(util.DefaultString(runtime.Ca, client.Ca)), @@ -755,28 +456,24 @@ func (client *Client) DoROARequest(action *string, version *string, protocol *st "socks5Proxy": tea.StringValue(util.DefaultString(runtime.Socks5Proxy, client.Socks5Proxy)), "socks5NetWork": tea.StringValue(util.DefaultString(runtime.Socks5NetWork, client.Socks5NetWork)), "maxIdleConns": tea.IntValue(util.DefaultNumber(runtime.MaxIdleConns, client.MaxIdleConns)), - "retry": map[string]interface{}{ - "retryable": tea.BoolValue(runtime.Autoretry), - "maxAttempts": tea.IntValue(util.DefaultNumber(runtime.MaxAttempts, tea.Int(3))), - }, - "backoff": map[string]interface{}{ - "policy": tea.StringValue(util.DefaultString(runtime.BackoffPolicy, tea.String("no"))), - "period": tea.IntValue(util.DefaultNumber(runtime.BackoffPeriod, tea.Int(1))), - }, - "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + "retryOptions": client.RetryOptions, + "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + }) + + var retryPolicyContext *tea.RetryPolicyContext + var request_ *tea.Request + var response_ *tea.Response + retriesAttempted := int(0) + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), } - _resp := make(map[string]interface{}) - for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ { - if _retryTimes > 0 { - _backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes)) - if tea.IntValue(_backoffTime) > 0 { - tea.Sleep(_backoffTime) - } - } + for tea.BoolValue(tea.ShouldRetry(_runtime.RetryOptions, retryPolicyContext)) { + _backoffDelayTime := tea.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext) + tea.Sleep(_backoffDelayTime) _resp, _err = func() (map[string]interface{}, error) { - request_ := tea.NewRequest() + request_ = tea.NewRequest() request_.Protocol = util.DefaultString(client.Protocol, protocol) request_.Method = method request_.Pathname = pathname @@ -867,15 +564,38 @@ func (client *Client) DoROARequest(action *string, version *string, protocol *st requestId := DefaultAny(err["RequestId"], err["requestId"]) requestId = DefaultAny(requestId, err["requestid"]) - err["statusCode"] = response_.StatusCode - _err = tea.NewSDKError(map[string]interface{}{ - "code": tea.ToString(DefaultAny(err["Code"], err["code"])), - "message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId), - "data": err, - "description": tea.ToString(DefaultAny(err["Description"], err["description"])), - "accessDeniedDetail": DefaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]), - }) - return _result, _err + code := DefaultAny(err["Code"], err["code"]) + if tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.User"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.Api"))) { + _err = &ThrottlingError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RetryAfter: openapiutil.GetThrottlingTimeLeft(response_.Headers), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else if tea.BoolValue(util.Is4xx(response_.StatusCode)) { + _err = &ClientError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + AccessDeniedDetail: client.GetAccessDeniedDetail(err), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else { + _err = &ServerError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } + } if tea.BoolValue(util.EqualString(bodyType, tea.String("binary"))) { @@ -953,27 +673,44 @@ func (client *Client) DoROARequest(action *string, version *string, protocol *st } }() - if !tea.BoolValue(tea.Retryable(_err)) { + if _err == nil { break } + retriesAttempted++ + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), + Request: request_, + Response: response_, + Error: _err, + } } return _resp, _err } -/** - * Encapsulate the request and invoke the network with form body - * @param action api name - * @param version product version - * @param protocol http or https - * @param method e.g. GET - * @param authType authorization type e.g. AK - * @param pathname pathname of every api - * @param bodyType response body type e.g. String - * @param request object of OpenApiRequest - * @param runtime which controls some details of call api, such as retry times - * @return the response - */ +// Description: +// +// Encapsulate the request and invoke the network with form body +// +// @param action - api name +// +// @param version - product version +// +// @param protocol - http or https +// +// @param method - e.g. GET +// +// @param authType - authorization type e.g. AK +// +// @param pathname - pathname of every api +// +// @param bodyType - response body type e.g. String +// +// @param request - object of OpenApiRequest +// +// @param runtime - which controls some details of call api, such as retry times +// +// @return the response func (client *Client) DoROARequestWithForm(action *string, version *string, protocol *string, method *string, authType *string, pathname *string, bodyType *string, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { _err = tea.Validate(request) if _err != nil { @@ -983,8 +720,7 @@ func (client *Client) DoROARequestWithForm(action *string, version *string, prot if _err != nil { return _result, _err } - _runtime := map[string]interface{}{ - "timeouted": "retry", + _runtime := tea.NewRuntimeObject(map[string]interface{}{ "key": tea.StringValue(util.DefaultString(runtime.Key, client.Key)), "cert": tea.StringValue(util.DefaultString(runtime.Cert, client.Cert)), "ca": tea.StringValue(util.DefaultString(runtime.Ca, client.Ca)), @@ -996,28 +732,24 @@ func (client *Client) DoROARequestWithForm(action *string, version *string, prot "socks5Proxy": tea.StringValue(util.DefaultString(runtime.Socks5Proxy, client.Socks5Proxy)), "socks5NetWork": tea.StringValue(util.DefaultString(runtime.Socks5NetWork, client.Socks5NetWork)), "maxIdleConns": tea.IntValue(util.DefaultNumber(runtime.MaxIdleConns, client.MaxIdleConns)), - "retry": map[string]interface{}{ - "retryable": tea.BoolValue(runtime.Autoretry), - "maxAttempts": tea.IntValue(util.DefaultNumber(runtime.MaxAttempts, tea.Int(3))), - }, - "backoff": map[string]interface{}{ - "policy": tea.StringValue(util.DefaultString(runtime.BackoffPolicy, tea.String("no"))), - "period": tea.IntValue(util.DefaultNumber(runtime.BackoffPeriod, tea.Int(1))), - }, - "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + "retryOptions": client.RetryOptions, + "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + }) + + var retryPolicyContext *tea.RetryPolicyContext + var request_ *tea.Request + var response_ *tea.Response + retriesAttempted := int(0) + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), } - _resp := make(map[string]interface{}) - for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ { - if _retryTimes > 0 { - _backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes)) - if tea.IntValue(_backoffTime) > 0 { - tea.Sleep(_backoffTime) - } - } + for tea.BoolValue(tea.ShouldRetry(_runtime.RetryOptions, retryPolicyContext)) { + _backoffDelayTime := tea.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext) + tea.Sleep(_backoffDelayTime) _resp, _err = func() (map[string]interface{}, error) { - request_ := tea.NewRequest() + request_ = tea.NewRequest() request_.Protocol = util.DefaultString(client.Protocol, protocol) request_.Method = method request_.Pathname = pathname @@ -1111,15 +843,39 @@ func (client *Client) DoROARequestWithForm(action *string, version *string, prot return _result, _err } - err["statusCode"] = response_.StatusCode - _err = tea.NewSDKError(map[string]interface{}{ - "code": tea.ToString(DefaultAny(err["Code"], err["code"])), - "message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(DefaultAny(err["RequestId"], err["requestId"])), - "data": err, - "description": tea.ToString(DefaultAny(err["Description"], err["description"])), - "accessDeniedDetail": DefaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]), - }) - return _result, _err + requestId := DefaultAny(err["RequestId"], err["requestId"]) + code := DefaultAny(err["Code"], err["code"]) + if tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.User"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.Api"))) { + _err = &ThrottlingError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RetryAfter: openapiutil.GetThrottlingTimeLeft(response_.Headers), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else if tea.BoolValue(util.Is4xx(response_.StatusCode)) { + _err = &ClientError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + AccessDeniedDetail: client.GetAccessDeniedDetail(err), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else { + _err = &ServerError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } + } if tea.BoolValue(util.EqualString(bodyType, tea.String("binary"))) { @@ -1197,26 +953,42 @@ func (client *Client) DoROARequestWithForm(action *string, version *string, prot } }() - if !tea.BoolValue(tea.Retryable(_err)) { + if _err == nil { break } + retriesAttempted++ + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), + Request: request_, + Response: response_, + Error: _err, + } } return _resp, _err } -/** - * Encapsulate the request and invoke the network - * @param action api name - * @param version product version - * @param protocol http or https - * @param method e.g. GET - * @param authType authorization type e.g. AK - * @param bodyType response body type e.g. String - * @param request object of OpenApiRequest - * @param runtime which controls some details of call api, such as retry times - * @return the response - */ +// Description: +// +// Encapsulate the request and invoke the network +// +// @param action - api name +// +// @param version - product version +// +// @param protocol - http or https +// +// @param method - e.g. GET +// +// @param authType - authorization type e.g. AK +// +// @param bodyType - response body type e.g. String +// +// @param request - object of OpenApiRequest +// +// @param runtime - which controls some details of call api, such as retry times +// +// @return the response func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { _err = tea.Validate(params) if _err != nil { @@ -1230,8 +1002,7 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime if _err != nil { return _result, _err } - _runtime := map[string]interface{}{ - "timeouted": "retry", + _runtime := tea.NewRuntimeObject(map[string]interface{}{ "key": tea.StringValue(util.DefaultString(runtime.Key, client.Key)), "cert": tea.StringValue(util.DefaultString(runtime.Cert, client.Cert)), "ca": tea.StringValue(util.DefaultString(runtime.Ca, client.Ca)), @@ -1243,28 +1014,24 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime "socks5Proxy": tea.StringValue(util.DefaultString(runtime.Socks5Proxy, client.Socks5Proxy)), "socks5NetWork": tea.StringValue(util.DefaultString(runtime.Socks5NetWork, client.Socks5NetWork)), "maxIdleConns": tea.IntValue(util.DefaultNumber(runtime.MaxIdleConns, client.MaxIdleConns)), - "retry": map[string]interface{}{ - "retryable": tea.BoolValue(runtime.Autoretry), - "maxAttempts": tea.IntValue(util.DefaultNumber(runtime.MaxAttempts, tea.Int(3))), - }, - "backoff": map[string]interface{}{ - "policy": tea.StringValue(util.DefaultString(runtime.BackoffPolicy, tea.String("no"))), - "period": tea.IntValue(util.DefaultNumber(runtime.BackoffPeriod, tea.Int(1))), - }, - "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + "retryOptions": client.RetryOptions, + "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + }) + + var retryPolicyContext *tea.RetryPolicyContext + var request_ *tea.Request + var response_ *tea.Response + retriesAttempted := int(0) + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), } - _resp := make(map[string]interface{}) - for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ { - if _retryTimes > 0 { - _backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes)) - if tea.IntValue(_backoffTime) > 0 { - tea.Sleep(_backoffTime) - } - } + for tea.BoolValue(tea.ShouldRetry(_runtime.RetryOptions, retryPolicyContext)) { + _backoffDelayTime := tea.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext) + tea.Sleep(_backoffDelayTime) _resp, _err = func() (map[string]interface{}, error) { - request_ := tea.NewRequest() + request_ = tea.NewRequest() request_.Protocol = util.DefaultString(client.Protocol, params.Protocol) request_.Method = params.Method request_.Pathname = params.Pathname @@ -1416,15 +1183,39 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime } - err["statusCode"] = response_.StatusCode - _err = tea.NewSDKError(map[string]interface{}{ - "code": tea.ToString(DefaultAny(err["Code"], err["code"])), - "message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(DefaultAny(err["RequestId"], err["requestId"])), - "data": err, - "description": tea.ToString(DefaultAny(err["Description"], err["description"])), - "accessDeniedDetail": DefaultAny(err["AccessDeniedDetail"], err["accessDeniedDetail"]), - }) - return _result, _err + requestId := DefaultAny(err["RequestId"], err["requestId"]) + code := DefaultAny(err["Code"], err["code"]) + if tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.User"))) || tea.BoolValue(util.EqualString(tea.String(tea.ToString(code)), tea.String("Throttling.Api"))) { + _err = &ThrottlingError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RetryAfter: openapiutil.GetThrottlingTimeLeft(response_.Headers), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else if tea.BoolValue(util.Is4xx(response_.StatusCode)) { + _err = &ClientError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + AccessDeniedDetail: client.GetAccessDeniedDetail(err), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } else { + _err = &ServerError{ + StatusCode: response_.StatusCode, + Code: tea.String(tea.ToString(code)), + Message: tea.String("code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(requestId)), + Description: tea.String(tea.ToString(DefaultAny(err["Description"], err["description"]))), + RequestId: tea.String(tea.ToString(requestId)), + } + return _result, _err + } + } if tea.BoolValue(util.EqualString(params.BodyType, tea.String("binary"))) { @@ -1508,26 +1299,42 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime } }() - if !tea.BoolValue(tea.Retryable(_err)) { + if _err == nil { break } + retriesAttempted++ + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), + Request: request_, + Response: response_, + Error: _err, + } } return _resp, _err } -/** - * Encapsulate the request and invoke the network - * @param action api name - * @param version product version - * @param protocol http or https - * @param method e.g. GET - * @param authType authorization type e.g. AK - * @param bodyType response body type e.g. String - * @param request object of OpenApiRequest - * @param runtime which controls some details of call api, such as retry times - * @return the response - */ +// Description: +// +// Encapsulate the request and invoke the network +// +// @param action - api name +// +// @param version - product version +// +// @param protocol - http or https +// +// @param method - e.g. GET +// +// @param authType - authorization type e.g. AK +// +// @param bodyType - response body type e.g. String +// +// @param request - object of OpenApiRequest +// +// @param runtime - which controls some details of call api, such as retry times +// +// @return the response func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { _err = tea.Validate(params) if _err != nil { @@ -1541,8 +1348,7 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * if _err != nil { return _result, _err } - _runtime := map[string]interface{}{ - "timeouted": "retry", + _runtime := tea.NewRuntimeObject(map[string]interface{}{ "key": tea.StringValue(util.DefaultString(runtime.Key, client.Key)), "cert": tea.StringValue(util.DefaultString(runtime.Cert, client.Cert)), "ca": tea.StringValue(util.DefaultString(runtime.Ca, client.Ca)), @@ -1554,25 +1360,21 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * "socks5Proxy": tea.StringValue(util.DefaultString(runtime.Socks5Proxy, client.Socks5Proxy)), "socks5NetWork": tea.StringValue(util.DefaultString(runtime.Socks5NetWork, client.Socks5NetWork)), "maxIdleConns": tea.IntValue(util.DefaultNumber(runtime.MaxIdleConns, client.MaxIdleConns)), - "retry": map[string]interface{}{ - "retryable": tea.BoolValue(runtime.Autoretry), - "maxAttempts": tea.IntValue(util.DefaultNumber(runtime.MaxAttempts, tea.Int(3))), - }, - "backoff": map[string]interface{}{ - "policy": tea.StringValue(util.DefaultString(runtime.BackoffPolicy, tea.String("no"))), - "period": tea.IntValue(util.DefaultNumber(runtime.BackoffPeriod, tea.Int(1))), - }, - "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + "retryOptions": client.RetryOptions, + "ignoreSSL": tea.BoolValue(runtime.IgnoreSSL), + }) + + var retryPolicyContext *tea.RetryPolicyContext + var request_ *tea.Request + var response_ *tea.Response + retriesAttempted := int(0) + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), } - _resp := make(map[string]interface{}) - for _retryTimes := 0; tea.BoolValue(tea.AllowRetry(_runtime["retry"], tea.Int(_retryTimes))); _retryTimes++ { - if _retryTimes > 0 { - _backoffTime := tea.GetBackoffTime(_runtime["backoff"], tea.Int(_retryTimes)) - if tea.IntValue(_backoffTime) > 0 { - tea.Sleep(_backoffTime) - } - } + for tea.BoolValue(tea.ShouldRetry(_runtime.RetryOptions, retryPolicyContext)) { + _backoffDelayTime := tea.GetBackoffDelay(_runtime.RetryOptions, retryPolicyContext) + tea.Sleep(_backoffDelayTime) _resp, _err = func() (map[string]interface{}, error) { request_ := tea.NewRequest() @@ -1673,9 +1475,16 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * }, &_result) return _result, _err }() - if !tea.BoolValue(tea.Retryable(_err)) { + if _err == nil { break } + retriesAttempted++ + retryPolicyContext = &tea.RetryPolicyContext{ + RetriesAttempted: tea.Int(retriesAttempted), + Request: request_, + Response: response_, + Error: _err, + } } return _resp, _err @@ -1683,10 +1492,10 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * func (client *Client) CallApi(params *Params, request *OpenApiRequest, runtime *util.RuntimeOptions) (_result map[string]interface{}, _err error) { if tea.BoolValue(util.IsUnset(params)) { - _err = tea.NewSDKError(map[string]interface{}{ - "code": "ParameterMissing", - "message": "'params' can not be unset", - }) + _err = &ClientError{ + Code: tea.String("ParameterMissing"), + Message: tea.String("'params' can not be unset"), + } return _result, _err } @@ -1726,20 +1535,22 @@ func (client *Client) CallApi(params *Params, request *OpenApiRequest, runtime * } -/** - * Get user agent - * @return user agent - */ +// Description: +// +// Get user agent +// +// @return user agent func (client *Client) GetUserAgent() (_result *string) { userAgent := util.GetUserAgent(client.UserAgent) _result = userAgent return _result } -/** - * Get accesskey id by using credential - * @return accesskey id - */ +// Description: +// +// Get accesskey id by using credential +// +// @return accesskey id func (client *Client) GetAccessKeyId() (_result *string, _err error) { if tea.BoolValue(util.IsUnset(client.Credential)) { _result = tea.String("") @@ -1755,10 +1566,11 @@ func (client *Client) GetAccessKeyId() (_result *string, _err error) { return _result, _err } -/** - * Get accesskey secret by using credential - * @return accesskey secret - */ +// Description: +// +// Get accesskey secret by using credential +// +// @return accesskey secret func (client *Client) GetAccessKeySecret() (_result *string, _err error) { if tea.BoolValue(util.IsUnset(client.Credential)) { _result = tea.String("") @@ -1774,10 +1586,11 @@ func (client *Client) GetAccessKeySecret() (_result *string, _err error) { return _result, _err } -/** - * Get security token by using credential - * @return security token - */ +// Description: +// +// Get security token by using credential +// +// @return security token func (client *Client) GetSecurityToken() (_result *string, _err error) { if tea.BoolValue(util.IsUnset(client.Credential)) { _result = tea.String("") @@ -1793,10 +1606,11 @@ func (client *Client) GetSecurityToken() (_result *string, _err error) { return _result, _err } -/** - * Get bearer token by credential - * @return bearer token - */ +// Description: +// +// Get bearer token by credential +// +// @return bearer token func (client *Client) GetBearerToken() (_result *string, _err error) { if tea.BoolValue(util.IsUnset(client.Credential)) { _result = tea.String("") @@ -1808,10 +1622,11 @@ func (client *Client) GetBearerToken() (_result *string, _err error) { return _result, _err } -/** - * Get credential type by credential - * @return credential type e.g. access_key - */ +// Description: +// +// Get credential type by credential +// +// @return credential type e.g. access_key func (client *Client) GetType() (_result *string, _err error) { if tea.BoolValue(util.IsUnset(client.Credential)) { _result = tea.String("") @@ -1823,12 +1638,15 @@ func (client *Client) GetType() (_result *string, _err error) { return _result, _err } -/** - * If inputValue is not null, return it or return defaultValue - * @param inputValue users input value - * @param defaultValue default value - * @return the final result - */ +// Description: +// +// If inputValue is not null, return it or return defaultValue +// +// @param inputValue - users input value +// +// @param defaultValue - default value +// +// @return the final result func DefaultAny(inputValue interface{}, defaultValue interface{}) (_result interface{}) { if tea.BoolValue(util.IsUnset(inputValue)) { _result = defaultValue @@ -1839,46 +1657,71 @@ func DefaultAny(inputValue interface{}, defaultValue interface{}) (_result inter return _result } -/** - * If the endpointRule and config.endpoint are empty, throw error - * @param config config contains the necessary information to create a client - */ +// Description: +// +// If the endpointRule and config.endpoint are empty, throw error +// +// @param config - config contains the necessary information to create a client func (client *Client) CheckConfig(config *Config) (_err error) { if tea.BoolValue(util.Empty(client.EndpointRule)) && tea.BoolValue(util.Empty(config.Endpoint)) { - _err = tea.NewSDKError(map[string]interface{}{ - "code": "ParameterMissing", - "message": "'config.endpoint' can not be empty", - }) + _err = &ClientError{ + Code: tea.String("ParameterMissing"), + Message: tea.String("'config.endpoint' can not be unset"), + } return _err } return _err } -/** - * set gateway client - * @param spi. - */ +// Description: +// +// set gateway client +// +// @param spi - . func (client *Client) SetGatewayClient(spi spi.ClientInterface) (_err error) { client.Spi = spi return _err } -/** - * set RPC header for debug - * @param headers headers for debug, this header can be used only once. - */ +// Description: +// +// set RPC header for debug +// +// @param headers - headers for debug, this header can be used only once. func (client *Client) SetRpcHeaders(headers map[string]*string) (_err error) { client.Headers = headers return _err } -/** - * get RPC header for debug - */ +// Description: +// +// get RPC header for debug func (client *Client) GetRpcHeaders() (_result map[string]*string, _err error) { headers := client.Headers client.Headers = nil _result = headers return _result, _err } + +func (client *Client) GetAccessDeniedDetail(err map[string]interface{}) (_result map[string]interface{}) { + var accessDeniedDetail map[string]interface{} + if tea.BoolValue(util.IsUnset(err["AccessDeniedDetail"])) { + detail1, _err := util.AssertAsMap(err["AccessDeniedDetail"]) + if _err != nil { + return _result + } + + accessDeniedDetail = detail1 + } else if tea.BoolValue(util.IsUnset(err["accessDeniedDetail"])) { + detail2, _err := util.AssertAsMap(err["AccessDeniedDetail"]) + if _err != nil { + return _result + } + + accessDeniedDetail = detail2 + } + + _result = accessDeniedDetail + return _result +} diff --git a/golang/client/client_test.go b/golang/client/client_test.go index 759db08..4405bb9 100644 --- a/golang/client/client_test.go +++ b/golang/client/client_test.go @@ -8,10 +8,10 @@ import ( "testing" "time" - openapiutil "github.com/alibabacloud-go/openapi-util/service" + openapiutil "github.com/alibabacloud-go/openapi-util/v2/service" util "github.com/alibabacloud-go/tea-utils/v2/service" - "github.com/alibabacloud-go/tea/tea" - tea_util "github.com/alibabacloud-go/tea/utils" + "github.com/alibabacloud-go/tea/v2/tea" + tea_util "github.com/alibabacloud-go/tea/v2/utils" credential "github.com/aliyun/credentials-go/credentials" ) @@ -61,6 +61,29 @@ func (mock *mockHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { ", \"Description\":\"error description\", \"accessDeniedDetail\":{\"test\": 0}}" w.WriteHeader(400) w.Write([]byte(responseBody)) + case "error3": + responseBody = "{\"Code\":\"Throttling\", \"Message\":\"Throttling error\", \"RequestId\":\"A45EE076-334D-5012-9746-A8F828D20FD4\"" + + ", \"Description\":\"Throttling error description\"}" + w.WriteHeader(429) + w.Write([]byte(responseBody)) + case "error4": + responseBody = "{\"Code\":\"Throttling\", \"Message\":\"Throttling error\", \"RequestId\":\"A45EE076-334D-5012-9746-A8F828D20FD4\"" + + ", \"Description\":\"Throttling error description\"}" + w.Header().Set("X-RateLimit-User", "Limit:1,Remain:0,TimeLeft:1000,Reset:1000") + w.WriteHeader(429) + w.Write([]byte(responseBody)) + case "error5": + responseBody = "{\"Code\":\"Throttling.User\", \"Message\":\"Throttling.User error\", \"RequestId\":\"A45EE076-334D-5012-9746-A8F828D20FD4\"" + + ", \"Description\":\"Throttling error description\"}" + w.Header().Set("X-RateLimit-User", "Limit:1,Remain:0,TimeLeft:2000,Reset:2000") + w.WriteHeader(429) + w.Write([]byte(responseBody)) + case "error6": + responseBody = "{\"Code\":\"Throttling.Api\", \"Message\":\"Throttling.Api error\", \"RequestId\":\"A45EE076-334D-5012-9746-A8F828D20FD4\"" + + ", \"Description\":\"Throttling.Api error description\"}" + w.Header().Set("X-RateLimit-User-API", "Limit:1,Remain:0,TimeLeft:3000,Reset:3000") + w.WriteHeader(429) + w.Write([]byte(responseBody)) default: w.WriteHeader(200) w.Write([]byte(responseBody)) @@ -723,6 +746,10 @@ func TestResponseBodyType(t *testing.T) { mux.Handle("/testError", &mockHandler{content: "error"}) mux.Handle("/testError1", &mockHandler{content: "error1"}) mux.Handle("/testError2", &mockHandler{content: "error2"}) + mux.Handle("/testError3", &mockHandler{content: "error3"}) + mux.Handle("/testError4", &mockHandler{content: "error4"}) + mux.Handle("/testError5", &mockHandler{content: "error5"}) + mux.Handle("/testError6", &mockHandler{content: "error6"}) var server *http.Server server = &http.Server{ Addr: ":9009", @@ -792,7 +819,7 @@ func TestResponseBodyType(t *testing.T) { }() tea_util.AssertNotNil(t, tryErr) - err := tryErr.(*tea.SDKError) + err := tryErr.(*ClientError) tea_util.AssertEqual(t, "code: 400, error message request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(err.Message)) tea_util.AssertEqual(t, 400, tea.IntValue(err.StatusCode)) @@ -813,7 +840,7 @@ func TestResponseBodyType(t *testing.T) { }() tea_util.AssertNotNil(t, tryErr) - err = tryErr.(*tea.SDKError) + err = tryErr.(*ClientError) tea_util.AssertEqual(t, "code: 400, error message request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(err.Message)) tea_util.AssertEqual(t, 400, tea.IntValue(err.StatusCode)) @@ -834,12 +861,96 @@ func TestResponseBodyType(t *testing.T) { }() tea_util.AssertNotNil(t, tryErr) - err = tryErr.(*tea.SDKError) + err = tryErr.(*ClientError) tea_util.AssertEqual(t, "code: 400, error message request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(err.Message)) tea_util.AssertEqual(t, 400, tea.IntValue(err.StatusCode)) accessDeniedDetail, _ := err.AccessDeniedDetail["test"].(int) tea_util.AssertEqual(t, 0, accessDeniedDetail) + + params.Pathname = tea.String("/testError3") + tryErr = func() (_e error) { + defer func() { + if r := tea.Recover(recover()); r != nil { + _e = r + } + }() + _, _err = client.CallApi(params, request, runtime) + if _err != nil { + return _err + } + return nil + }() + + tea_util.AssertNotNil(t, tryErr) + throttlingError := tryErr.(*ThrottlingError) + tea_util.AssertEqual(t, "code: 429, Throttling error request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(throttlingError.Message)) + + tea_util.AssertEqual(t, 429, tea.IntValue(throttlingError.StatusCode)) + tea_util.AssertNil(t, throttlingError.RetryAfter) + + params.Pathname = tea.String("/testError4") + tryErr = func() (_e error) { + defer func() { + if r := tea.Recover(recover()); r != nil { + _e = r + } + }() + _, _err = client.CallApi(params, request, runtime) + if _err != nil { + return _err + } + return nil + }() + + tea_util.AssertNotNil(t, tryErr) + throttlingError = tryErr.(*ThrottlingError) + tea_util.AssertEqual(t, "code: 429, Throttling error request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(throttlingError.Message)) + + tea_util.AssertEqual(t, 429, tea.IntValue(throttlingError.StatusCode)) + tea_util.AssertEqual(t, int64(1000), tea.Int64Value(throttlingError.RetryAfter)) + + params.Pathname = tea.String("/testError5") + tryErr = func() (_e error) { + defer func() { + if r := tea.Recover(recover()); r != nil { + _e = r + } + }() + _, _err = client.CallApi(params, request, runtime) + if _err != nil { + return _err + } + return nil + }() + + tea_util.AssertNotNil(t, tryErr) + throttlingError = tryErr.(*ThrottlingError) + tea_util.AssertEqual(t, "code: 429, Throttling.User error request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(throttlingError.Message)) + + tea_util.AssertEqual(t, 429, tea.IntValue(throttlingError.StatusCode)) + tea_util.AssertEqual(t, int64(2000), tea.Int64Value(throttlingError.RetryAfter)) + + params.Pathname = tea.String("/testError6") + tryErr = func() (_e error) { + defer func() { + if r := tea.Recover(recover()); r != nil { + _e = r + } + }() + _, _err = client.CallApi(params, request, runtime) + if _err != nil { + return _err + } + return nil + }() + + tea_util.AssertNotNil(t, tryErr) + throttlingError = tryErr.(*ThrottlingError) + tea_util.AssertEqual(t, "code: 429, Throttling.Api error request id: A45EE076-334D-5012-9746-A8F828D20FD4", tea.StringValue(throttlingError.Message)) + + tea_util.AssertEqual(t, 429, tea.IntValue(throttlingError.StatusCode)) + tea_util.AssertEqual(t, int64(3000), tea.Int64Value(throttlingError.RetryAfter)) } func TestRequestBodyType(t *testing.T) { diff --git a/golang/client/errors.go b/golang/client/errors.go new file mode 100644 index 0000000..f5156e7 --- /dev/null +++ b/golang/client/errors.go @@ -0,0 +1,129 @@ +package client + +import ( + "github.com/alibabacloud-go/tea/v2/tea" +) + +type AlibabaCloudError struct { + tea.BaseError + // HTTP Status Code + StatusCode *int + // Error Code + Code *string + // Error Message + Message *string + // Error Description + Description *string + // Request ID + RequestId *string +} + +func (err *AlibabaCloudError) Error() string { + return tea.Prettify(err) +} + +func (err *AlibabaCloudError) ErrorName() *string { + return tea.String("AlibabaCloudError") +} + +func (err *AlibabaCloudError) ErrorCode() *string { + return err.Code +} + +func (err *AlibabaCloudError) RetryAfterTimeMillis() *int64 { + return nil +} + +type ClientError struct { + *AlibabaCloudError + // HTTP Status Code + StatusCode *int + // Error Code + Code *string + // Error Message + Message *string + // Error Description + Description *string + // Request ID + RequestId *string + // Access Denied Detail + AccessDeniedDetail map[string]interface{} +} + +func (err *ClientError) Error() string { + return tea.Prettify(err) +} + +func (err *ClientError) ErrorName() *string { + return tea.String("ClientError") +} + +func (err *ClientError) ErrorCode() *string { + return err.Code +} + +func (err *ClientError) RetryAfterTimeMillis() *int64 { + return nil +} + +type ServerError struct { + *AlibabaCloudError + // HTTP Status Code + StatusCode *int + // Error Code + Code *string + // Error Message + Message *string + // Error Description + Description *string + // Request ID + RequestId *string +} + +func (err *ServerError) Error() string { + return tea.Prettify(err) +} + +func (err *ServerError) ErrorName() *string { + return tea.String("ServerError") +} + +func (err *ServerError) ErrorCode() *string { + return err.Code +} + +func (err *ServerError) RetryAfterTimeMillis() *int64 { + return nil +} + +type ThrottlingError struct { + *AlibabaCloudError + // HTTP Status Code + StatusCode *int + // Error Code + Code *string + // Error Message + Message *string + // Error Description + Description *string + // Request ID + RequestId *string + // Retry After(ms) + RetryAfter *int64 +} + +func (err *ThrottlingError) Error() string { + return tea.Prettify(err) +} + +func (err *ThrottlingError) ErrorName() *string { + return tea.String("ThrottlingError") +} + +func (err *ThrottlingError) ErrorCode() *string { + return err.Code +} + +func (err *ThrottlingError) RetryAfterTimeMillis() *int64 { + return err.RetryAfter +} diff --git a/golang/client/errors_test.go b/golang/client/errors_test.go new file mode 100644 index 0000000..aae1a07 --- /dev/null +++ b/golang/client/errors_test.go @@ -0,0 +1,47 @@ +package client + +import ( + "testing" + + "github.com/alibabacloud-go/tea/v2/tea" + "github.com/alibabacloud-go/tea/v2/utils" +) + +func TestThrottlingError(t *testing.T) { + var err tea.BaseError + err = &ThrottlingError{ + Code: tea.String("Throttling"), + Message: tea.String("message"), + Description: tea.String("Throttling"), + StatusCode: tea.Int(int(429)), + RetryAfter: tea.Int64(int64(2000)), + } + utils.AssertNotNil(t, err) + utils.AssertEqual(t, tea.Prettify(err), err.Error()) + utils.AssertEqual(t, "Throttling", tea.StringValue(err.ErrorCode())) + utils.AssertEqual(t, "ThrottlingError", tea.StringValue(err.ErrorName())) + utils.AssertEqual(t, int64(2000), tea.Int64Value(err.RetryAfterTimeMillis())) + throttlingError, ok := err.(*ThrottlingError) + utils.AssertEqual(t, true, ok) + + utils.AssertEqual(t, tea.Prettify(throttlingError), throttlingError.Error()) + utils.AssertEqual(t, "Throttling", tea.StringValue(throttlingError.ErrorCode())) + utils.AssertEqual(t, "ThrottlingError", tea.StringValue(throttlingError.ErrorName())) + utils.AssertEqual(t, int64(2000), tea.Int64Value(throttlingError.RetryAfterTimeMillis())) + utils.AssertEqual(t, "Throttling", tea.StringValue(throttlingError.Code)) + utils.AssertEqual(t, "message", tea.StringValue(throttlingError.Message)) + utils.AssertEqual(t, "Throttling", tea.StringValue(throttlingError.Description)) + utils.AssertEqual(t, int(429), tea.IntValue(throttlingError.StatusCode)) + utils.AssertEqual(t, int64(2000), tea.Int64Value(throttlingError.RetryAfter)) + + throttlingError = &ThrottlingError{} + utils.AssertEqual(t, tea.Prettify(throttlingError), throttlingError.Error()) + utils.AssertNil(t, throttlingError.ErrorCode()) + utils.AssertEqual(t, "ThrottlingError", tea.StringValue(throttlingError.ErrorName())) + utils.AssertNil(t, throttlingError.RetryAfterTimeMillis()) + utils.AssertNil(t, throttlingError.Code) + utils.AssertNil(t, throttlingError.Message) + utils.AssertNil(t, throttlingError.Description) + utils.AssertNil(t, throttlingError.StatusCode) + utils.AssertNil(t, throttlingError.RetryAfter) +} diff --git a/golang/client/models.go b/golang/client/models.go new file mode 100644 index 0000000..2b00916 --- /dev/null +++ b/golang/client/models.go @@ -0,0 +1,465 @@ +package client + +import ( + "io" + + "github.com/alibabacloud-go/tea/v2/tea" + credential "github.com/aliyun/credentials-go/credentials" +) + +type GlobalParameters struct { + Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` + Queries map[string]*string `json:"queries,omitempty" xml:"queries,omitempty"` +} + +func (s GlobalParameters) String() string { + return tea.Prettify(s) +} + +func (s GlobalParameters) GoString() string { + return s.String() +} + +func (s *GlobalParameters) SetHeaders(v map[string]*string) *GlobalParameters { + s.Headers = v + return s +} + +func (s *GlobalParameters) SetQueries(v map[string]*string) *GlobalParameters { + s.Queries = v + return s +} + +// Description: +// +// Model for initing client +type Config struct { + // accesskey id + AccessKeyId *string `json:"accessKeyId,omitempty" xml:"accessKeyId,omitempty"` + // accesskey secret + AccessKeySecret *string `json:"accessKeySecret,omitempty" xml:"accessKeySecret,omitempty"` + // security token + SecurityToken *string `json:"securityToken,omitempty" xml:"securityToken,omitempty"` + // http protocol + // + // example: + // + // http + Protocol *string `json:"protocol,omitempty" xml:"protocol,omitempty"` + // http method + // + // example: + // + // GET + Method *string `json:"method,omitempty" xml:"method,omitempty"` + // region id + // + // example: + // + // cn-hangzhou + RegionId *string `json:"regionId,omitempty" xml:"regionId,omitempty"` + // read timeout + // + // example: + // + // 10 + ReadTimeout *int `json:"readTimeout,omitempty" xml:"readTimeout,omitempty"` + // connect timeout + // + // example: + // + // 10 + ConnectTimeout *int `json:"connectTimeout,omitempty" xml:"connectTimeout,omitempty"` + // http proxy + // + // example: + // + // http://localhost + HttpProxy *string `json:"httpProxy,omitempty" xml:"httpProxy,omitempty"` + // https proxy + // + // example: + // + // https://localhost + HttpsProxy *string `json:"httpsProxy,omitempty" xml:"httpsProxy,omitempty"` + // credential + Credential credential.Credential `json:"credential,omitempty" xml:"credential,omitempty"` + // endpoint + // + // example: + // + // cs.aliyuncs.com + Endpoint *string `json:"endpoint,omitempty" xml:"endpoint,omitempty"` + // proxy white list + // + // example: + // + // http://localhost + NoProxy *string `json:"noProxy,omitempty" xml:"noProxy,omitempty"` + // max idle conns + // + // example: + // + // 3 + MaxIdleConns *int `json:"maxIdleConns,omitempty" xml:"maxIdleConns,omitempty"` + // network for endpoint + // + // example: + // + // public + Network *string `json:"network,omitempty" xml:"network,omitempty"` + // user agent + // + // example: + // + // Alibabacloud/1 + UserAgent *string `json:"userAgent,omitempty" xml:"userAgent,omitempty"` + // suffix for endpoint + // + // example: + // + // aliyun + Suffix *string `json:"suffix,omitempty" xml:"suffix,omitempty"` + // socks5 proxy + Socks5Proxy *string `json:"socks5Proxy,omitempty" xml:"socks5Proxy,omitempty"` + // socks5 network + // + // example: + // + // TCP + Socks5NetWork *string `json:"socks5NetWork,omitempty" xml:"socks5NetWork,omitempty"` + // endpoint type + // + // example: + // + // internal + EndpointType *string `json:"endpointType,omitempty" xml:"endpointType,omitempty"` + // OpenPlatform endpoint + // + // example: + // + // openplatform.aliyuncs.com + OpenPlatformEndpoint *string `json:"openPlatformEndpoint,omitempty" xml:"openPlatformEndpoint,omitempty"` + // Deprecated + // + // credential type + // + // example: + // + // access_key + Type *string `json:"type,omitempty" xml:"type,omitempty"` + // Signature Version + // + // example: + // + // v1 + SignatureVersion *string `json:"signatureVersion,omitempty" xml:"signatureVersion,omitempty"` + // Signature Algorithm + // + // example: + // + // ACS3-HMAC-SHA256 + SignatureAlgorithm *string `json:"signatureAlgorithm,omitempty" xml:"signatureAlgorithm,omitempty"` + // Global Parameters + GlobalParameters *GlobalParameters `json:"globalParameters,omitempty" xml:"globalParameters,omitempty"` + // privite key for client certificate + // + // example: + // + // MIIEvQ + Key *string `json:"key,omitempty" xml:"key,omitempty"` + // client certificate + // + // example: + // + // -----BEGIN CERTIFICATE----- + // + // xxx-----END CERTIFICATE----- + Cert *string `json:"cert,omitempty" xml:"cert,omitempty"` + // server certificate + // + // example: + // + // -----BEGIN CERTIFICATE----- + // + // xxx-----END CERTIFICATE----- + Ca *string `json:"ca,omitempty" xml:"ca,omitempty"` + // disable HTTP/2 + // + // example: + // + // false + DisableHttp2 *bool `json:"disableHttp2,omitempty" xml:"disableHttp2,omitempty"` + // retry options + RetryOptions *tea.RetryOptions `json:"retryOptions,omitempty" xml:"retryOptions,omitempty"` +} + +func (s Config) String() string { + return tea.Prettify(s) +} + +func (s Config) GoString() string { + return s.String() +} + +func (s *Config) SetAccessKeyId(v string) *Config { + s.AccessKeyId = &v + return s +} + +func (s *Config) SetAccessKeySecret(v string) *Config { + s.AccessKeySecret = &v + return s +} + +func (s *Config) SetSecurityToken(v string) *Config { + s.SecurityToken = &v + return s +} + +func (s *Config) SetProtocol(v string) *Config { + s.Protocol = &v + return s +} + +func (s *Config) SetMethod(v string) *Config { + s.Method = &v + return s +} + +func (s *Config) SetRegionId(v string) *Config { + s.RegionId = &v + return s +} + +func (s *Config) SetReadTimeout(v int) *Config { + s.ReadTimeout = &v + return s +} + +func (s *Config) SetConnectTimeout(v int) *Config { + s.ConnectTimeout = &v + return s +} + +func (s *Config) SetHttpProxy(v string) *Config { + s.HttpProxy = &v + return s +} + +func (s *Config) SetHttpsProxy(v string) *Config { + s.HttpsProxy = &v + return s +} + +func (s *Config) SetCredential(v credential.Credential) *Config { + s.Credential = v + return s +} + +func (s *Config) SetEndpoint(v string) *Config { + s.Endpoint = &v + return s +} + +func (s *Config) SetNoProxy(v string) *Config { + s.NoProxy = &v + return s +} + +func (s *Config) SetMaxIdleConns(v int) *Config { + s.MaxIdleConns = &v + return s +} + +func (s *Config) SetNetwork(v string) *Config { + s.Network = &v + return s +} + +func (s *Config) SetUserAgent(v string) *Config { + s.UserAgent = &v + return s +} + +func (s *Config) SetSuffix(v string) *Config { + s.Suffix = &v + return s +} + +func (s *Config) SetSocks5Proxy(v string) *Config { + s.Socks5Proxy = &v + return s +} + +func (s *Config) SetSocks5NetWork(v string) *Config { + s.Socks5NetWork = &v + return s +} + +func (s *Config) SetEndpointType(v string) *Config { + s.EndpointType = &v + return s +} + +func (s *Config) SetOpenPlatformEndpoint(v string) *Config { + s.OpenPlatformEndpoint = &v + return s +} + +func (s *Config) SetType(v string) *Config { + s.Type = &v + return s +} + +func (s *Config) SetSignatureVersion(v string) *Config { + s.SignatureVersion = &v + return s +} + +func (s *Config) SetSignatureAlgorithm(v string) *Config { + s.SignatureAlgorithm = &v + return s +} + +func (s *Config) SetGlobalParameters(v *GlobalParameters) *Config { + s.GlobalParameters = v + return s +} + +func (s *Config) SetKey(v string) *Config { + s.Key = &v + return s +} + +func (s *Config) SetCert(v string) *Config { + s.Cert = &v + return s +} + +func (s *Config) SetCa(v string) *Config { + s.Ca = &v + return s +} + +func (s *Config) SetDisableHttp2(v bool) *Config { + s.DisableHttp2 = &v + return s +} + +func (s *Config) SetRetryOptions(v *tea.RetryOptions) *Config { + s.RetryOptions = v + return s +} + +type OpenApiRequest struct { + Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` + Query map[string]*string `json:"query,omitempty" xml:"query,omitempty"` + Body interface{} `json:"body,omitempty" xml:"body,omitempty"` + Stream io.Reader `json:"stream,omitempty" xml:"stream,omitempty"` + HostMap map[string]*string `json:"hostMap,omitempty" xml:"hostMap,omitempty"` + EndpointOverride *string `json:"endpointOverride,omitempty" xml:"endpointOverride,omitempty"` +} + +func (s OpenApiRequest) String() string { + return tea.Prettify(s) +} + +func (s OpenApiRequest) GoString() string { + return s.String() +} + +func (s *OpenApiRequest) SetHeaders(v map[string]*string) *OpenApiRequest { + s.Headers = v + return s +} + +func (s *OpenApiRequest) SetQuery(v map[string]*string) *OpenApiRequest { + s.Query = v + return s +} + +func (s *OpenApiRequest) SetBody(v interface{}) *OpenApiRequest { + s.Body = v + return s +} + +func (s *OpenApiRequest) SetStream(v io.Reader) *OpenApiRequest { + s.Stream = v + return s +} + +func (s *OpenApiRequest) SetHostMap(v map[string]*string) *OpenApiRequest { + s.HostMap = v + return s +} + +func (s *OpenApiRequest) SetEndpointOverride(v string) *OpenApiRequest { + s.EndpointOverride = &v + return s +} + +type Params struct { + Action *string `json:"action,omitempty" xml:"action,omitempty" require:"true"` + Version *string `json:"version,omitempty" xml:"version,omitempty" require:"true"` + Protocol *string `json:"protocol,omitempty" xml:"protocol,omitempty" require:"true"` + Pathname *string `json:"pathname,omitempty" xml:"pathname,omitempty" require:"true"` + Method *string `json:"method,omitempty" xml:"method,omitempty" require:"true"` + AuthType *string `json:"authType,omitempty" xml:"authType,omitempty" require:"true"` + BodyType *string `json:"bodyType,omitempty" xml:"bodyType,omitempty" require:"true"` + ReqBodyType *string `json:"reqBodyType,omitempty" xml:"reqBodyType,omitempty" require:"true"` + Style *string `json:"style,omitempty" xml:"style,omitempty"` +} + +func (s Params) String() string { + return tea.Prettify(s) +} + +func (s Params) GoString() string { + return s.String() +} + +func (s *Params) SetAction(v string) *Params { + s.Action = &v + return s +} + +func (s *Params) SetVersion(v string) *Params { + s.Version = &v + return s +} + +func (s *Params) SetProtocol(v string) *Params { + s.Protocol = &v + return s +} + +func (s *Params) SetPathname(v string) *Params { + s.Pathname = &v + return s +} + +func (s *Params) SetMethod(v string) *Params { + s.Method = &v + return s +} + +func (s *Params) SetAuthType(v string) *Params { + s.AuthType = &v + return s +} + +func (s *Params) SetBodyType(v string) *Params { + s.BodyType = &v + return s +} + +func (s *Params) SetReqBodyType(v string) *Params { + s.ReqBodyType = &v + return s +} + +func (s *Params) SetStyle(v string) *Params { + s.Style = &v + return s +} diff --git a/golang/go.mod b/golang/go.mod index e6b1c93..8fdb343 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -1,14 +1,13 @@ -module github.com/alibabacloud-go/darabonba-openapi/v2 +module github.com/alibabacloud-go/darabonba-openapi/v3 go 1.14 require ( github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 - github.com/alibabacloud-go/openapi-util v0.1.0 - github.com/alibabacloud-go/tea v1.2.1 + github.com/alibabacloud-go/openapi-util/v2 v2.0.0-20240320061419-781b7331e4e8 // indirect github.com/alibabacloud-go/tea-utils/v2 v2.0.5 github.com/alibabacloud-go/tea-xml v1.1.3 + github.com/alibabacloud-go/tea/v2 v2.0.0-20240319132217-8ac445bc69ba // indirect github.com/aliyun/credentials-go v1.3.1 github.com/clbanning/mxj/v2 v2.5.5 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect ) diff --git a/main.tea b/main.tea index 86e3954..ff49635 100644 --- a/main.tea +++ b/main.tea @@ -38,18 +38,43 @@ type @key = string type @cert = string type @ca = string type @disableHttp2 = boolean +type @retryOptions = $RetryOptions model GlobalParameters { headers?: map[string]string, queries?: map[string]string, } + +@aliasName("AlibabaCloudException") +exception AlibabaCloudError extends $Error { + statusCode?: number(description='HTTP Status Code'), + code?: string(description="Error Code"), + message?: string(description="Error Message"), + description?: string(description="Error Description"), + requestId?: string(description="Request ID"), +} + +@aliasName("ClientException") +exception ClientError extends AlibabaCloudError { + accessDeniedDetail?: map[string]any(description="Access Denied Detail"), +} + +@aliasName("ServerException") +exception ServerError extends AlibabaCloudError { +} + +@aliasName("ThrottlingException") +exception ThrottlingError extends AlibabaCloudError { + retryAfter?: long(description="Retry After(ms)"), +} + /** * Model for initing client */ model Config { accessKeyId?: string(description='accesskey id',default=''), accessKeySecret?: string(description='accesskey secret',default=''), - securityToken?: string(description='security token',example='a.txt',default=''), + securityToken?: string(description='security token',example='',default=''), protocol?: string(description='http protocol',example='http',default='http'), method?: string(description='http method',example='GET',default=''), regionId?: string(description='region id',example='cn-hangzhou',default=''), @@ -76,6 +101,7 @@ model Config { cert?: string(description='client certificate', example='-----BEGIN CERTIFICATE-----\nxxx-----END CERTIFICATE-----',default=''), ca?: string(description='server certificate', example='-----BEGIN CERTIFICATE-----\nxxx-----END CERTIFICATE-----',default=''), disableHttp2?: boolean(description='disable HTTP/2', example='false'), + retryOptions?: $RetryOptions(description='retry options'), } /** @@ -84,7 +110,7 @@ model Config { */ init(config: Config) { if (Util.isUnset(config)) { - throw { + throw new ClientError { code = 'ParameterMissing', message = '\'config\' can not be unset' }; @@ -129,6 +155,7 @@ init(config: Config) { @cert = config.cert; @ca = config.ca; @disableHttp2 = config.disableHttp2; + @retryOptions = config.retryOptions; } model OpenApiRequest { @@ -234,14 +261,34 @@ api doRPCRequest(action: string, version: string, protocol: string, method: stri var _res = Util.readAsJSON(__response.body); var err = Util.assertAsMap(_res); var requestId = defaultAny(err.RequestId, err.requestId); - err.statusCode = __response.statusCode; - throw { - code = `${defaultAny(err.Code, err.code)}`, - message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, - data = err, - description = `${defaultAny(err.Description, err.description)}`, - accessDeniedDetail = defaultAny(err.AccessDeniedDetail, err.accessDeniedDetail), - }; + var code = defaultAny(err.Code, err.code); + if (Util.equalString(`${code}`, 'Throttling') || Util.equalString(`${code}`, 'Throttling.User') || Util.equalString(`${code}`, 'Throttling.Api')) { + throw new ThrottlingError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + retryAfter = OpenApiUtil.getThrottlingTimeLeft(__response.headers), + requestId = `${requestId}`, + }; + } else if (Util.is4xx(__response.statusCode)) { + throw new ClientError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + accessDeniedDetail = getAccessDeniedDetail(err), + requestId = `${requestId}`, + }; + } else { + throw new ServerError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + requestId = `${requestId}`, + }; + } } if (Util.equalString(bodyType, 'binary')) { var resp = { @@ -286,7 +333,6 @@ api doRPCRequest(action: string, version: string, protocol: string, method: stri }; } } runtime { - timeouted = 'retry', key = Util.defaultString(runtime.key, @key), cert = Util.defaultString(runtime.cert, @cert), ca = Util.defaultString(runtime.ca, @ca), @@ -298,14 +344,7 @@ api doRPCRequest(action: string, version: string, protocol: string, method: stri socks5Proxy = Util.defaultString(runtime.socks5Proxy, @socks5Proxy), socks5NetWork = Util.defaultString(runtime.socks5NetWork, @socks5NetWork), maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns), - retry = { - retryable = runtime.autoretry, - maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3) - }, - backoff = { - policy = Util.defaultString(runtime.backoffPolicy, 'no'), - period = Util.defaultNumber(runtime.backoffPeriod, 1) - }, + retryOptions = @retryOptions, ignoreSSL = runtime.ignoreSSL } @@ -388,14 +427,34 @@ api doROARequest(action: string, version: string, protocol: string, method: stri var err = Util.assertAsMap(_res); var requestId = defaultAny(err.RequestId, err.requestId); requestId = defaultAny(requestId, err.requestid); - err.statusCode = __response.statusCode; - throw { - code = `${defaultAny(err.Code, err.code)}`, - message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, - data = err, - description = `${defaultAny(err.Description, err.description)}`, - accessDeniedDetail = defaultAny(err.AccessDeniedDetail, err.accessDeniedDetail), - }; + var code = defaultAny(err.Code, err.code); + if (Util.equalString(`${code}`, 'Throttling') || Util.equalString(`${code}`, 'Throttling.User') || Util.equalString(`${code}`, 'Throttling.Api')) { + throw new ThrottlingError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + retryAfter = OpenApiUtil.getThrottlingTimeLeft(__response.headers), + requestId = `${requestId}`, + }; + } else if (Util.is4xx(__response.statusCode)) { + throw new ClientError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + accessDeniedDetail = getAccessDeniedDetail(err), + requestId = `${requestId}`, + }; + } else { + throw new ServerError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + requestId = `${requestId}`, + }; + } } if (Util.equalString(bodyType, 'binary')) { var resp = { @@ -440,7 +499,6 @@ api doROARequest(action: string, version: string, protocol: string, method: stri }; } } runtime { - timeouted = 'retry', key = Util.defaultString(runtime.key, @key), cert = Util.defaultString(runtime.cert, @cert), ca = Util.defaultString(runtime.ca, @ca), @@ -452,14 +510,7 @@ api doROARequest(action: string, version: string, protocol: string, method: stri socks5Proxy = Util.defaultString(runtime.socks5Proxy, @socks5Proxy), socks5NetWork = Util.defaultString(runtime.socks5NetWork, @socks5NetWork), maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns), - retry = { - retryable = runtime.autoretry, - maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3) - }, - backoff = { - policy = Util.defaultString(runtime.backoffPolicy, 'no'), - period = Util.defaultNumber(runtime.backoffPeriod, 1) - }, + retryOptions = @retryOptions, ignoreSSL = runtime.ignoreSSL } @@ -542,14 +593,35 @@ api doROARequestWithForm(action: string, version: string, protocol: string, meth if (Util.is4xx(__response.statusCode) || Util.is5xx(__response.statusCode)) { var _res = Util.readAsJSON(__response.body); var err = Util.assertAsMap(_res); - err.statusCode = __response.statusCode; - throw { - code = `${defaultAny(err.Code, err.code)}`, - message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${defaultAny(err.RequestId, err.requestId)}`, - data = err, - description = `${defaultAny(err.Description, err.description)}`, - accessDeniedDetail = defaultAny(err.AccessDeniedDetail, err.accessDeniedDetail), - }; + var requestId = defaultAny(err.RequestId, err.requestId); + var code = defaultAny(err.Code, err.code); + if (Util.equalString(`${code}`, 'Throttling') || Util.equalString(`${code}`, 'Throttling.User') || Util.equalString(`${code}`, 'Throttling.Api')) { + throw new ThrottlingError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + retryAfter = OpenApiUtil.getThrottlingTimeLeft(__response.headers), + requestId = `${requestId}`, + }; + } else if (Util.is4xx(__response.statusCode)) { + throw new ClientError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + accessDeniedDetail = getAccessDeniedDetail(err), + requestId = `${requestId}`, + }; + } else { + throw new ServerError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + requestId = `${requestId}`, + }; + } } if (Util.equalString(bodyType, 'binary')) { var resp = { @@ -594,7 +666,6 @@ api doROARequestWithForm(action: string, version: string, protocol: string, meth }; } } runtime { - timeouted = 'retry', key = Util.defaultString(runtime.key, @key), cert = Util.defaultString(runtime.cert, @cert), ca = Util.defaultString(runtime.ca, @ca), @@ -606,14 +677,7 @@ api doROARequestWithForm(action: string, version: string, protocol: string, meth socks5Proxy = Util.defaultString(runtime.socks5Proxy, @socks5Proxy), socks5NetWork = Util.defaultString(runtime.socks5NetWork, @socks5NetWork), maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns), - retry = { - retryable = runtime.autoretry, - maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3) - }, - backoff = { - policy = Util.defaultString(runtime.backoffPolicy, 'no'), - period = Util.defaultNumber(runtime.backoffPeriod, 1) - }, + retryOptions = @retryOptions, ignoreSSL = runtime.ignoreSSL } @@ -631,7 +695,7 @@ model Params = { async function callApi(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOptions): object { if (Util.isUnset(params)) { - throw { + throw new ClientError { code = 'ParameterMissing', message = '\'params\' can not be unset' }; @@ -768,14 +832,35 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti var _res = Util.readAsJSON(__response.body); err = Util.assertAsMap(_res); } - err.statusCode = __response.statusCode; - throw { - code = `${defaultAny(err.Code, err.code)}`, - message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${defaultAny(err.RequestId, err.requestId)}`, - data = err, - description = `${defaultAny(err.Description, err.description)}`, - accessDeniedDetail = defaultAny(err.AccessDeniedDetail, err.accessDeniedDetail), - }; + var requestId = defaultAny(err.RequestId, err.requestId); + var code = defaultAny(err.Code, err.code); + if (Util.equalString(`${code}`, 'Throttling') || Util.equalString(`${code}`, 'Throttling.User') || Util.equalString(`${code}`, 'Throttling.Api')) { + throw new ThrottlingError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + retryAfter = OpenApiUtil.getThrottlingTimeLeft(__response.headers), + requestId = `${requestId}`, + }; + } else if (Util.is4xx(__response.statusCode)) { + throw new ClientError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + accessDeniedDetail = getAccessDeniedDetail(err), + requestId = `${requestId}`, + }; + } else { + throw new ServerError{ + statusCode = __response.statusCode, + code = `${code}`, + message = `code: ${__response.statusCode}, ${defaultAny(err.Message, err.message)} request id: ${requestId}`, + description = `${defaultAny(err.Description, err.description)}`, + requestId = `${requestId}`, + }; + } } if (Util.equalString(params.bodyType, 'binary')) { var resp = { @@ -822,7 +907,6 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti }; } } runtime { - timeouted = 'retry', key = Util.defaultString(runtime.key, @key), cert = Util.defaultString(runtime.cert, @cert), ca = Util.defaultString(runtime.ca, @ca), @@ -834,14 +918,7 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti socks5Proxy = Util.defaultString(runtime.socks5Proxy, @socks5Proxy), socks5NetWork = Util.defaultString(runtime.socks5NetWork, @socks5NetWork), maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns), - retry = { - retryable = runtime.autoretry, - maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3) - }, - backoff = { - policy = Util.defaultString(runtime.backoffPolicy, 'no'), - period = Util.defaultNumber(runtime.backoffPeriod, 1) - }, + retryOptions = @retryOptions, ignoreSSL = runtime.ignoreSSL } @@ -946,7 +1023,6 @@ api execute(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOption }; } runtime { - timeouted = 'retry', key = Util.defaultString(runtime.key, @key), cert = Util.defaultString(runtime.cert, @cert), ca = Util.defaultString(runtime.ca, @ca), @@ -958,14 +1034,7 @@ api execute(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOption socks5Proxy = Util.defaultString(runtime.socks5Proxy, @socks5Proxy), socks5NetWork = Util.defaultString(runtime.socks5NetWork, @socks5NetWork), maxIdleConns = Util.defaultNumber(runtime.maxIdleConns, @maxIdleConns), - retry = { - retryable = runtime.autoretry, - maxAttempts = Util.defaultNumber(runtime.maxAttempts, 3) - }, - backoff = { - policy = Util.defaultString(runtime.backoffPolicy, 'no'), - period = Util.defaultNumber(runtime.backoffPeriod, 1) - }, + retryOptions = @retryOptions, ignoreSSL = runtime.ignoreSSL, disableHttp2 = defaultAny(@disableHttp2, false) } @@ -1058,7 +1127,7 @@ static function defaultAny(inputValue: any, defaultValue: any): any { */ function checkConfig(config: Config)throws : void { if (Util.empty(@endpointRule) && Util.empty(config.endpoint)) { - throw { + throw new ClientError { code = 'ParameterMissing', message = '\'config.endpoint\' can not be empty' }; @@ -1089,3 +1158,15 @@ function getRpcHeaders() throws : map[string] string { @headers = null; return headers; } + +function getAccessDeniedDetail(err: map[string] any): map[string] any { + var accessDeniedDetail : map[string] any = null; + if (Util.isUnset(err.AccessDeniedDetail)) { + var detail1 = Util.assertAsMap(err.AccessDeniedDetail); + accessDeniedDetail = detail1; + } else if (Util.isUnset(err.accessDeniedDetail)) { + var detail2 = Util.assertAsMap(err.AccessDeniedDetail); + accessDeniedDetail = detail2; + } + return accessDeniedDetail; +}