Compare commits

...

58 Commits

Author SHA1 Message Date
yndu13 8ac445bc69 [v2.x]Rebuild retry policy 2024-03-19 21:22:17 +08:00
dependabot[bot] bb7ae5fd3e disable fail-fast 2024-01-22 17:30:17 +08:00
dependabot[bot] c1f8e32399 Bump github.com/alibabacloud-go/debug
Bumps [github.com/alibabacloud-go/debug](https://github.com/alibabacloud-go/debug) from 0.0.0-20190504072949-9472017b5c68 to 1.0.0.
- [Release notes](https://github.com/alibabacloud-go/debug/releases)
- [Commits](https://github.com/alibabacloud-go/debug/commits/v1.0.0)

---
updated-dependencies:
- dependency-name: github.com/alibabacloud-go/debug
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-22 17:17:14 +08:00
dependabot[bot] d755295be2 Bump golang.org/x/net from 0.11.0 to 0.20.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.11.0 to 0.20.0.
- [Commits](https://github.com/golang/net/compare/v0.11.0...v0.20.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-22 17:14:25 +08:00
yndu13 b81493c626 fix: unescape unicode in sdk error 2024-01-22 17:12:09 +08:00
nanhe 2b0e131d00 docs: update comments 2023-06-28 17:46:15 +08:00
nanhe e3922d2afb improve tls client config 2023-06-28 17:31:08 +08:00
dependabot[bot] 5ef2fcc54f Bump golang.org/x/net from 0.10.0 to 0.11.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.10.0 to 0.11.0.
- [Commits](https://github.com/golang/net/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-27 23:13:13 +08:00
Jackson Tian 121efa4413 update actions setup-go to v4 2023-05-15 15:40:51 +08:00
dependabot[bot] aa99f50b3f Bump golang.org/x/net from 0.9.0 to 0.10.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.9.0 to 0.10.0.
- [Commits](https://github.com/golang/net/compare/v0.9.0...v0.10.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-15 15:36:25 +08:00
王理想 cb3a42bc23 judge maxidleconns int(0) pointer 2023-05-08 16:52:58 +08:00
王理想 712238a5c4 remove keep alive default 2023-05-08 16:52:58 +08:00
王理想 07ca3b69ad deal with MaxIdleConns, MaxIdleConnsPerHost, TLSHandshakeTimeout, and KeepAlive 2023-05-08 16:52:58 +08:00
dependabot[bot] e158cc5dc5 Bump golang.org/x/net from 0.0.0-20200226121028-0de0cce0169b to 0.9.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.0.0-20200226121028-0de0cce0169b to 0.9.0.
- [Release notes](https://github.com/golang/net/releases)
- [Commits](https://github.com/golang/net/commits/v0.9.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-26 11:32:33 +08:00
dependabot[bot] b46b464236 Bump github.com/json-iterator/go from 1.1.10 to 1.1.12
Bumps [github.com/json-iterator/go](https://github.com/json-iterator/go) from 1.1.10 to 1.1.12.
- [Release notes](https://github.com/json-iterator/go/releases)
- [Commits](https://github.com/json-iterator/go/compare/v1.1.10...v1.1.12)

---
updated-dependencies:
- dependency-name: github.com/json-iterator/go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-26 11:29:32 +08:00
Jackson Tian 636d89faa7 Create dependabot.yml 2023-04-26 11:27:59 +08:00
Jackson Tian c4f78703d7 Update README-CN.md 2023-04-26 11:21:46 +08:00
Jackson Tian 8a7c8512f8 Update README.md 2023-04-26 11:21:33 +08:00
Jackson Tian 02f393be3f Delete .travis.yml 2023-03-23 15:12:14 +08:00
nanhe c87ce79386 support port for url request 2023-03-23 15:01:26 +08:00
nanhe b9ace42a5b feat: return description and accessDeniedDetail in error info 2022-10-20 15:56:55 +08:00
nanhe 3a75a83be1 support when statusCode is *int 2022-06-20 20:19:19 +08:00
nanhe af66437067 support statusCode in data for SDKError 2022-06-14 16:16:13 +08:00
nanhe e0a739a681 add Action 2022-06-14 16:16:13 +08:00
ziggy d9ff2bfbeb add StatusCode for SDK Error
Co-authored-by: zigang.wang <zigang.wang@alibaba-inc.com>
2021-07-23 13:54:08 +08:00
peze fc13b6ebee fix the big number unmarshal error 2021-05-19 09:42:26 +08:00
wb-wzc505509 6355725204 modify Convert 2021-01-26 17:34:04 +08:00
wb-wzc505509 b6aa048c4a add ToInt and ToInt32 2021-01-18 09:45:18 +08:00
wb-wzc505509 5da4c33a57 rm port 2021-01-06 14:42:54 +08:00
wb-wzc505509 2a316b984d support ignore tag 2021-01-05 09:21:42 +08:00
wb-wzc505509 fa780870a7 fix pattern error 2020-11-30 13:12:50 +08:00
wb-wzc505509 9144ca7f27 support ssl 2020-10-19 13:36:46 +08:00
wb-wzc505509 174725cf27 add more basic type 2020-09-08 10:08:47 +08:00
wb-wzc505509 45df60e197 FixUserAgentError 2020-09-07 14:56:23 +08:00
wb-wzc505509 ecd18128a4 add slice validate 2020-08-21 17:24:40 +08:00
wb-wzc505509 f16f5b0116 improve test 2020-07-16 15:41:36 +08:00
wb-wzc505509 8291a17aca validate support null param 2020-07-09 13:52:35 +08:00
wb-wzc505509 7ad16974b6 validate support null param 2020-07-09 13:39:59 +08:00
wb-wzc505509 8918f7f891 fix timeout error 2020-07-08 17:20:59 +08:00
wb-wzc505509 29a23a75ba add recover 2020-07-06 10:25:53 +08:00
wb-wzc505509 d9c5d0857b add SetErrMsg to SDKError 2020-07-03 13:21:52 +08:00
wb-wzc505509 852924e5df fix the error caused by omitempty 2020-06-22 13:03:43 +08:00
wenzuochao 4c13582572 support validate minLength minimum maxmum 2020-05-13 14:31:45 +08:00
wenzuochao d3a7dc916c fix error 2020-05-11 12:44:54 +08:00
wenzuochao 8817d0e413 supoort MapValuePointer 2020-05-09 14:25:17 +08:00
wenzuochao da2886ab11 modify map value type 2020-05-08 10:57:55 +08:00
wenzuochao 3618315947 support pointer 2020-04-20 17:27:21 +08:00
wenzuochao 28a4a7b309 fixToMapError 2020-04-13 14:10:07 +08:00
wenzuochao 4d8a89852b fixToMapError 2020-04-03 10:26:35 +08:00
wenzuochao 60574a9378 modify tomap 2020-04-03 10:17:26 +08:00
wenzuochao 2a388c0108 update checkMaxLength 2020-03-20 15:21:05 +08:00
wenzuochao 268f040e48 modify checkMaxLength 2020-03-20 13:05:33 +08:00
wenzuochao b56effc83d modify host 2020-03-12 11:17:26 +08:00
wenzuochao f4dd763f32 modify dorequest 2020-03-11 19:46:00 +08:00
wenzuochao d369dc9ebb modifyToMap 2020-03-02 17:19:27 +08:00
wenzuochao 781d370215 modify tomap 2020-03-02 15:41:47 +08:00
wenzuochao b8b38f5032 improve 2020-02-24 19:00:52 +08:00
wenzuochao d9f729f559 modifyToMap 2020-02-24 16:03:24 +08:00
41 changed files with 4427 additions and 2731 deletions
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
+36
View File
@@ -0,0 +1,36 @@
name: Go CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.13", "1.14", "1.15", "1.16", "1.17", "1.18", "1.19", "1.20"]
fail-fast: false
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build Tea
run: go build ./tea
- name: Build Util
run: go build ./utils
- name: Test
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./tea/... ./utils/...
- name: CodeCov
run: bash <(curl -s https://codecov.io/bash)
-28
View File
@@ -1,28 +0,0 @@
language: go
go:
- 1.10.x
- 1.11.x
- 1.12.x
branches: # build only on these branches
only:
- master
install:
- go get -u github.com/golang/dep/cmd/dep
- dep ensure
notifications:
webhooks: https://oapi.dingtalk.com/robot/send?access_token=096ed387df243a6d60835aadeccc47165f3813bc7cb81cdd0cfeadfd28e3acc1
email: false
on_success: change
on_failure: always
script:
- go vet ./tea/...
- go vet ./utils/...
- go test -race -coverprofile=coverage.txt -covermode=atomic ./tea/... ./utils/...
after_success:
- bash <(curl -s https://codecov.io/bash)
Generated
-31
View File
@@ -1,31 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
digest = "1:95a5d3b703c5a42a670bae2643f87f9d1009051cf8657b628945fb4022ab4de0"
name = "github.com/alibabacloud-go/debug"
packages = ["debug"]
pruneopts = "UT"
revision = "9472017b5c6804c66e5d873fabd2a2a937b31e0b"
[[projects]]
branch = "master"
digest = "1:3587bbb18e3d5299dc0020733e2839138afb0a29456ffd4073a3962bb9966556"
name = "golang.org/x/net"
packages = [
"internal/socks",
"proxy",
]
pruneopts = "UT"
revision = "72f939374954d0a1b2a1e27dcda950e2724dd5c1"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/alibabacloud-go/debug/debug",
"golang.org/x/net/proxy",
]
solver-name = "gps-cdcl"
solver-version = 1
-38
View File
@@ -1,38 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
branch = "master"
name = "github.com/alibabacloud-go/debug"
[[constraint]]
branch = "master"
name = "golang.org/x/net"
[prune]
go-tests = true
unused-packages = true
+3 -3
View File
@@ -2,11 +2,11 @@
<a href="https://badge.fury.io/gh/alibabacloud-go%2Ftea"><img src="https://badge.fury.io/gh/alibabacloud-go%2Ftea.svg" alt="Latest Stable Version"></a>
<a href="https://codecov.io/gh/alibabacloud-go/tea"><img src="https://codecov.io/gh/alibabacloud-go/tea/branch/master/graph/badge.svg" alt="codecov"></a>
<a href="https://travis-ci.org/alibabacloud-go/tea"><img src="https://travis-ci.org/alibabacloud-go/tea.svg?branch=master" alt="Travis Build Status"></a>
[![Go CI](https://github.com/alibabacloud-go/tea/actions/workflows/go.yml/badge.svg)](https://github.com/alibabacloud-go/tea/actions/workflows/go.yml)
该项目用于支持TEA OpenAPI DSL。它是http请求的底层库.
该项目用于支持 Darabonba OpenAPI DSL。它是http请求的底层库.
## 许可证
[Apache-2.0](/LICENSE)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
+3 -3
View File
@@ -2,11 +2,11 @@
<a href="https://badge.fury.io/gh/alibabacloud-go%2Ftea"><img src="https://badge.fury.io/gh/alibabacloud-go%2Ftea.svg" alt="Latest Stable Version"></a>
<a href="https://codecov.io/gh/alibabacloud-go/tea"><img src="https://codecov.io/gh/alibabacloud-go/tea/branch/master/graph/badge.svg" alt="codecov"></a>
<a href="https://travis-ci.org/alibabacloud-go/tea"><img src="https://travis-ci.org/alibabacloud-go/tea.svg?branch=master" alt="Travis Build Status"></a>
[![Go CI](https://github.com/alibabacloud-go/tea/actions/workflows/go.yml/badge.svg)](https://github.com/alibabacloud-go/tea/actions/workflows/go.yml)
This project is used for support TEA OpenAPI DSL. It's a low-level library for http request.
This project is used for support Darabonba OpenAPI DSL. It's a low-level library for http request.
## License
[Apache-2.0](/LICENSE)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
+10
View File
@@ -0,0 +1,10 @@
module github.com/alibabacloud-go/tea/v2
go 1.14
require (
github.com/alibabacloud-go/debug v1.0.0
github.com/json-iterator/go v1.1.12
github.com/modern-go/reflect2 v1.0.2
golang.org/x/net v0.20.0
)
+57
View File
@@ -0,0 +1,57 @@
github.com/alibabacloud-go/debug v1.0.0 h1:3eIEQWfay1fB24PQIEzXAswlVJtdQok8f3EVN5VrBnA=
github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+117
View File
@@ -0,0 +1,117 @@
package tea
import (
"math"
"math/rand"
)
type BackoffPolicy interface {
GetDelayTimeMillis(ctx *RetryPolicyContext) *int64
}
func NewBackoffPolicy(options map[string]interface{}) (backoffPolicy BackoffPolicy) {
policy := StringValue(TransInterfaceToString(options["policy"]))
switch policy {
case "Fixed":
backoffPolicy = &FixedBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
}
return
case "Random":
backoffPolicy = &RandomBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
case "Exponential":
backoffPolicy = &ExponentialBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
case "EqualJitter":
backoffPolicy = &EqualJitterBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
case "ExponentialWithEqualJitter":
backoffPolicy = &EqualJitterBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
case "FullJitter":
backoffPolicy = &FullJitterBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
case "ExponentialWithFullJitter":
backoffPolicy = &FullJitterBackoffPolicy{
Period: TransInterfaceToInt(options["period"]),
Cap: TransInterfaceToInt64(options["cap"]),
}
return
}
return nil
}
type FixedBackoffPolicy struct {
Period *int
}
func (fixedBackoff *FixedBackoffPolicy) GetDelayTimeMillis(ctx *RetryPolicyContext) *int64 {
return Int64(int64(IntValue(fixedBackoff.Period)))
}
type RandomBackoffPolicy struct {
Period *int
Cap *int64
}
func (randomBackoff *RandomBackoffPolicy) GetDelayTimeMillis(ctx *RetryPolicyContext) *int64 {
if randomBackoff.Cap == nil {
randomBackoff.Cap = Int64(20 * 1000)
}
ceil := math.Min(float64(*randomBackoff.Cap), float64(IntValue(randomBackoff.Period))*float64(IntValue(ctx.RetriesAttempted)))
return Int64(int64(rand.Float64() * ceil))
}
type ExponentialBackoffPolicy struct {
Period *int
Cap *int64
}
func (exponentialBackoff *ExponentialBackoffPolicy) GetDelayTimeMillis(ctx *RetryPolicyContext) *int64 {
if exponentialBackoff.Cap == nil {
exponentialBackoff.Cap = Int64(3 * 24 * 60 * 60 * 1000)
}
return Int64(int64(math.Min(float64(*exponentialBackoff.Cap), float64(IntValue(exponentialBackoff.Period))*math.Pow(2.0, float64(IntValue(ctx.RetriesAttempted))))))
}
type EqualJitterBackoffPolicy struct {
Period *int
Cap *int64
}
func (equalJitterBackoff *EqualJitterBackoffPolicy) GetDelayTimeMillis(ctx *RetryPolicyContext) *int64 {
if equalJitterBackoff.Cap == nil {
equalJitterBackoff.Cap = Int64(3 * 24 * 60 * 60 * 1000)
}
ceil := math.Min(float64(*equalJitterBackoff.Cap), float64(IntValue(equalJitterBackoff.Period))*math.Pow(2.0, float64(IntValue(ctx.RetriesAttempted))))
return Int64(int64(ceil/2 + rand.Float64()*(ceil/2+1)))
}
type FullJitterBackoffPolicy struct {
Period *int
Cap *int64
}
func (fullJitterBackof *FullJitterBackoffPolicy) GetDelayTimeMillis(ctx *RetryPolicyContext) *int64 {
if fullJitterBackof.Cap == nil {
fullJitterBackof.Cap = Int64(3 * 24 * 60 * 60 * 1000)
}
ceil := math.Min(float64(*fullJitterBackof.Cap), float64(IntValue(fullJitterBackof.Period))*math.Pow(2.0, float64(IntValue(ctx.RetriesAttempted))))
return Int64(int64(rand.Float64() * ceil))
}
+135
View File
@@ -0,0 +1,135 @@
package tea
import (
"reflect"
"testing"
"github.com/alibabacloud-go/tea/v2/utils"
)
func TestBackoffPolicy(t *testing.T) {
var backoffPolicy BackoffPolicy
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "Any",
})
utils.AssertEqual(t, nil, backoffPolicy)
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "Fixed",
"period": 1000,
})
typeOfPolicy := reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "FixedBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "Random",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "RandomBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "Exponential",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "ExponentialBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "EqualJitter",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "EqualJitterBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "ExponentialWithEqualJitter",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "EqualJitterBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "FullJitter",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "FullJitterBackoffPolicy", typeOfPolicy.Elem().Name())
backoffPolicy = NewBackoffPolicy(map[string]interface{}{
"policy": "ExponentialWithFullJitter",
"period": 2,
"cap": int64(60 * 1000),
})
typeOfPolicy = reflect.TypeOf(backoffPolicy)
utils.AssertEqual(t, "FullJitterBackoffPolicy", typeOfPolicy.Elem().Name())
}
func TestFixedBackoffPolicy(t *testing.T) {
backoffPolicy := FixedBackoffPolicy{
Period: Int(1000),
}
utils.AssertEqual(t, int64(1000), Int64Value(backoffPolicy.GetDelayTimeMillis(nil)))
retryPolicyContext := RetryPolicyContext{
RetriesAttempted: Int(1),
}
utils.AssertEqual(t, int64(1000), Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)))
retryPolicyContext = RetryPolicyContext{
RetriesAttempted: Int(2),
}
utils.AssertEqual(t, int64(1000), Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)))
}
func TestRandomBackoffPolicy(t *testing.T) {
backoffPolicy := RandomBackoffPolicy{
Period: Int(2),
}
retryPolicyContext := RetryPolicyContext{
RetriesAttempted: Int(1),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 2)
retryPolicyContext = RetryPolicyContext{
RetriesAttempted: Int(2),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 4)
}
func TestExponentialBackoffPolicy(t *testing.T) {
backoffPolicy := ExponentialBackoffPolicy{
Period: Int(2),
}
retryPolicyContext := RetryPolicyContext{
RetriesAttempted: Int(1),
}
utils.AssertEqual(t, int64(4), Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)))
retryPolicyContext = RetryPolicyContext{
RetriesAttempted: Int(2),
}
utils.AssertEqual(t, int64(8), Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)))
}
func TestEqualJitterBackoffPolicy(t *testing.T) {
backoffPolicy := EqualJitterBackoffPolicy{
Period: Int(2),
}
retryPolicyContext := RetryPolicyContext{
RetriesAttempted: Int(1),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 5)
retryPolicyContext = RetryPolicyContext{
RetriesAttempted: Int(2),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 9)
}
func TestFullJitterBackoffPolicy(t *testing.T) {
backoffPolicy := FullJitterBackoffPolicy{
Period: Int(2),
}
retryPolicyContext := RetryPolicyContext{
RetriesAttempted: Int(1),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 4)
retryPolicyContext = RetryPolicyContext{
RetriesAttempted: Int(2),
}
utils.AssertEqual(t, true, Int64Value(backoffPolicy.GetDelayTimeMillis(&retryPolicyContext)) < 8)
}
+896
View File
File diff suppressed because it is too large Load Diff
+629
View File
File diff suppressed because it is too large Load Diff
+152
View File
@@ -0,0 +1,152 @@
package tea
import (
"bytes"
"encoding/json"
"fmt"
"reflect"
"strconv"
)
// BaseError is an interface for getting actual error
type BaseError interface {
error
ErrorName() *string
ErrorCode() *string
RetryAfterTimeMillis() *int64
}
// CastError is used for cast type fails
type CastError struct {
Message *string
Code *string
}
// NewCastError is used for cast type fails
func NewCastError(message *string) *CastError {
return &CastError{
Message: message,
Code: nil,
}
}
// Return message of CastError
func (err *CastError) Error() string {
return StringValue(err.Message)
}
func (err *CastError) ErrorName() *string {
return String("CastError")
}
func (err *CastError) ErrorCode() *string {
return err.Code
}
func (err *CastError) RetryAfterTimeMillis() *int64 {
return nil
}
// SDKError struct is used save error code and message
type SDKError struct {
Code *string
StatusCode *int
Message *string
Data *string
Stack *string
errMsg *string
Description *string
AccessDeniedDetail map[string]interface{}
}
// NewSDKError is used for shortly create SDKError object
func NewSDKError(obj map[string]interface{}) *SDKError {
err := &SDKError{}
if val, ok := obj["code"].(int); ok {
err.Code = String(strconv.Itoa(val))
} else if val, ok := obj["code"].(string); ok {
err.Code = String(val)
}
if obj["message"] != nil {
err.Message = String(obj["message"].(string))
}
if obj["description"] != nil {
err.Description = String(obj["description"].(string))
}
if detail := obj["accessDeniedDetail"]; detail != nil {
r := reflect.ValueOf(detail)
if r.Kind().String() == "map" {
res := make(map[string]interface{})
tmp := r.MapKeys()
for _, key := range tmp {
res[key.String()] = r.MapIndex(key).Interface()
}
err.AccessDeniedDetail = res
}
}
if data := obj["data"]; data != nil {
r := reflect.ValueOf(data)
if r.Kind().String() == "map" {
res := make(map[string]interface{})
tmp := r.MapKeys()
for _, key := range tmp {
res[key.String()] = r.MapIndex(key).Interface()
}
if statusCode := res["statusCode"]; statusCode != nil {
if code, ok := statusCode.(int); ok {
err.StatusCode = Int(code)
} else if tmp, ok := statusCode.(string); ok {
code, err_ := strconv.Atoi(tmp)
if err_ == nil {
err.StatusCode = Int(code)
}
} else if code, ok := statusCode.(*int); ok {
err.StatusCode = code
}
}
}
byt := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(byt)
jsonEncoder.SetEscapeHTML(false)
jsonEncoder.Encode(data)
err.Data = String(string(bytes.TrimSpace(byt.Bytes())))
}
if statusCode, ok := obj["statusCode"].(int); ok {
err.StatusCode = Int(statusCode)
} else if status, ok := obj["statusCode"].(string); ok {
statusCode, err_ := strconv.Atoi(status)
if err_ == nil {
err.StatusCode = Int(statusCode)
}
}
return err
}
// Set ErrMsg by msg
func (err *SDKError) SetErrMsg(msg string) {
err.errMsg = String(msg)
}
func (err *SDKError) Error() string {
if err.errMsg == nil {
str := fmt.Sprintf("SDKError:\n StatusCode: %d\n Code: %s\n Message: %s\n Data: %s\n",
IntValue(err.StatusCode), StringValue(err.Code), StringValue(err.Message), StringValue(err.Data))
err.SetErrMsg(str)
}
return StringValue(err.errMsg)
}
func (err *SDKError) ErrorName() *string {
return String("SDKError")
}
func (err *SDKError) ErrorCode() *string {
return err.Code
}
func (err *SDKError) RetryAfterTimeMillis() *int64 {
return nil
}
+115
View File
@@ -0,0 +1,115 @@
package tea
import (
"testing"
"github.com/alibabacloud-go/tea/v2/utils"
)
func TestCastError(t *testing.T) {
var err BaseError
err = NewCastError(String("cast error"))
utils.AssertEqual(t, "cast error", err.Error())
utils.AssertEqual(t, "", StringValue(err.ErrorCode()))
utils.AssertEqual(t, "CastError", StringValue(err.ErrorName()))
utils.AssertNil(t, err.RetryAfterTimeMillis())
}
func TestSDKError(t *testing.T) {
var err0 BaseError
err0 = NewSDKError(map[string]interface{}{
"code": "code",
"statusCode": 404,
"message": "message",
"data": map[string]interface{}{
"httpCode": "404",
"requestId": "dfadfa32cgfdcasd4313",
"hostId": "github.com/alibabacloud/tea",
"recommend": "https://中文?q=a.b&product=c&requestId=123",
},
"description": "description",
"accessDeniedDetail": map[string]interface{}{
"AuthAction": "ram:ListUsers",
"AuthPrincipalType": "SubUser",
"PolicyType": "ResourceGroupLevelIdentityBassdPolicy",
"NoPermissionType": "ImplicitDeny",
"UserId": 123,
},
})
utils.AssertNotNil(t, err0)
utils.AssertEqual(t, "SDKError:\n StatusCode: 404\n Code: code\n Message: message\n Data: {\"hostId\":\"github.com/alibabacloud/tea\",\"httpCode\":\"404\",\"recommend\":\"https://中文?q=a.b&product=c&requestId=123\",\"requestId\":\"dfadfa32cgfdcasd4313\"}\n", err0.Error())
var err *SDKError
err = err0.(*SDKError)
err.SetErrMsg("test")
utils.AssertEqual(t, "test", err.Error())
utils.AssertEqual(t, 404, *err.StatusCode)
utils.AssertEqual(t, "description", *err.Description)
utils.AssertEqual(t, "ImplicitDeny", err.AccessDeniedDetail["NoPermissionType"])
utils.AssertEqual(t, 123, err.AccessDeniedDetail["UserId"])
utils.AssertNil(t, err.RetryAfterTimeMillis())
err = NewSDKError(map[string]interface{}{
"statusCode": "404",
"data": map[string]interface{}{
"statusCode": 500,
},
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, 404, *err.StatusCode)
err = NewSDKError(map[string]interface{}{
"data": map[string]interface{}{
"statusCode": 500,
},
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, 500, *err.StatusCode)
err = NewSDKError(map[string]interface{}{
"data": map[string]interface{}{
"statusCode": Int(500),
},
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, 500, *err.StatusCode)
err = NewSDKError(map[string]interface{}{
"data": map[string]interface{}{
"statusCode": "500",
},
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, 500, *err.StatusCode)
err = NewSDKError(map[string]interface{}{
"code": "code",
"message": "message",
"data": map[string]interface{}{
"requestId": "dfadfa32cgfdcasd4313",
},
})
utils.AssertNotNil(t, err)
utils.AssertNil(t, err.StatusCode)
err = NewSDKError(map[string]interface{}{
"code": 400,
"message": "message",
"data": "string data",
})
utils.AssertNotNil(t, err)
utils.AssertNotNil(t, err.Data)
utils.AssertEqual(t, "400", StringValue(err.Code))
utils.AssertNil(t, err.StatusCode)
}
func TestSDKErrorCode404(t *testing.T) {
err := NewSDKError(map[string]interface{}{
"statusCode": 404,
"code": "NOTFOUND",
"message": "message",
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, "SDKError:\n StatusCode: 404\n Code: NOTFOUND\n Message: message\n Data: \n", err.Error())
utils.AssertEqual(t, "NOTFOUND", StringValue(err.ErrorCode()))
utils.AssertEqual(t, "SDKError", StringValue(err.ErrorName()))
}
+81
View File
@@ -0,0 +1,81 @@
package tea
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
)
func Prettify(i interface{}) string {
resp, _ := json.MarshalIndent(i, "", " ")
return string(resp)
}
func Sleep(backoffTime *int64) {
sleeptime := time.Duration(Int64Value(backoffTime)) * time.Millisecond
time.Sleep(sleeptime)
}
func Merge(args ...interface{}) map[string]*string {
finalArg := make(map[string]*string)
for _, obj := range args {
switch obj.(type) {
case map[string]*string:
arg := obj.(map[string]*string)
for key, value := range arg {
if value != nil {
finalArg[key] = value
}
}
default:
byt, _ := json.Marshal(obj)
arg := make(map[string]string)
err := json.Unmarshal(byt, &arg)
if err != nil {
return finalArg
}
for key, value := range arg {
if value != "" {
finalArg[key] = String(value)
}
}
}
}
return finalArg
}
// Convert is use convert map[string]interface object to struct
func Convert(in interface{}, out interface{}) error {
byt, _ := json.Marshal(in)
decoder := jsonParser.NewDecoder(bytes.NewReader(byt))
decoder.UseNumber()
err := decoder.Decode(&out)
return err
}
// Recover is used to format error
func Recover(in interface{}) error {
if in == nil {
return nil
}
return errors.New(fmt.Sprint(in))
}
// Deprecated
func Retryable(err error) *bool {
if err == nil {
return Bool(false)
}
if realErr, ok := err.(*SDKError); ok {
if realErr.StatusCode == nil {
return Bool(false)
}
code := IntValue(realErr.StatusCode)
return Bool(code >= http.StatusInternalServerError)
}
return Bool(true)
}
+132
View File
@@ -0,0 +1,132 @@
package tea
import (
"errors"
"testing"
"time"
"github.com/alibabacloud-go/tea/v2/utils"
)
type PrettifyTest struct {
name string
Strs []string
Nums8 []int8
Unum8 []uint8
Value string
Mapvalue map[string]string
}
func Test_Prettify(t *testing.T) {
prettifyTest := &PrettifyTest{
name: "prettify",
Nums8: []int8{0, 1, 2, 4},
Unum8: []uint8{0},
Value: "ok",
Mapvalue: map[string]string{"key": "ccp", "value": "ok"},
}
str := Prettify(prettifyTest)
utils.AssertContains(t, str, "Nums8")
str = Prettify(nil)
utils.AssertEqual(t, str, "null")
}
func Test_Sleep(t *testing.T) {
start := time.Now()
Sleep(Int64(1000))
Sleep(Int64(0))
Sleep(nil)
cost := time.Since(start)
utils.AssertEqual(t, cost.Seconds() >= 1, true)
}
func Test_Merge(t *testing.T) {
in := map[string]*string{
"tea": String("test"),
}
valid := map[string]interface{}{
"valid": "test",
}
invalidStr := "sdfdg"
result := Merge(in, valid, invalidStr)
utils.AssertEqual(t, "test", StringValue(result["tea"]))
utils.AssertEqual(t, "test", StringValue(result["valid"]))
result = Merge(nil)
utils.AssertEqual(t, map[string]*string{}, result)
}
func Test_Convert(t *testing.T) {
in := map[string]interface{}{
"key": "value",
"body": []byte("test"),
}
out := new(test)
err := Convert(in, &out)
utils.AssertNil(t, err)
utils.AssertEqual(t, "value", out.Key)
utils.AssertEqual(t, "test", string(out.Body))
in = map[string]interface{}{
"key": 123,
"body": []byte("test"),
}
out = new(test)
err = Convert(in, &out)
utils.AssertNil(t, err)
utils.AssertEqual(t, "123", out.Key)
utils.AssertEqual(t, "test", string(out.Body))
}
func Test_Recover(t *testing.T) {
err := Recover(nil)
utils.AssertNil(t, err)
defer func() {
if r := Recover(recover()); r != nil {
utils.AssertEqual(t, "test", r.Error())
}
}()
panic("test")
}
func Test_Retryable(t *testing.T) {
ifRetry := Retryable(nil)
utils.AssertEqual(t, false, BoolValue(ifRetry))
err := errors.New("tea")
ifRetry = Retryable(err)
utils.AssertEqual(t, true, BoolValue(ifRetry))
errmsg := map[string]interface{}{
"code": "err",
}
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, false, BoolValue(ifRetry))
errmsg["statusCode"] = 400
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, false, BoolValue(ifRetry))
errmsg["statusCode"] = "400"
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, false, BoolValue(ifRetry))
errmsg["statusCode"] = 500
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, true, BoolValue(ifRetry))
errmsg["statusCode"] = "500"
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, true, BoolValue(ifRetry))
errmsg["statusCode"] = "test"
err = NewSDKError(errmsg)
ifRetry = Retryable(err)
utils.AssertEqual(t, false, BoolValue(ifRetry))
}
+333
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+107
View File
@@ -0,0 +1,107 @@
package tea
import (
"math"
"time"
"github.com/alibabacloud-go/tea/v2/utils"
)
const (
// DefaultMaxAttempts sets maximum number of retries
DefaultMaxAttempts = 3
// DefaultMinDelay sets minimum retry delay
DefaultMinDelay = 100 * time.Millisecond
// DefaultMaxDelayTimeMillis sets maximum retry delay
DefaultMaxDelay = 120 * time.Second
)
type RetryCondition struct {
MaxAttempts *int
MaxDelayTimeMillis *int64
Backoff *BackoffPolicy
Exception []*string
ErrorCode []*string
}
type RetryOptions struct {
Retryable *bool
RetryCondition []*RetryCondition
NoRetryCondition []*RetryCondition
}
type RetryPolicyContext struct {
RetriesAttempted *int
Request *Request
Response *Response
Error error
}
func ShouldRetry(options *RetryOptions, ctx *RetryPolicyContext) *bool {
if IntValue(ctx.RetriesAttempted) == 0 {
return Bool(true)
}
if options == nil || !BoolValue(options.Retryable) {
return Bool(false)
}
if err, ok := ctx.Error.(BaseError); ok {
noRetryConditions := options.NoRetryCondition
retryConditions := options.RetryCondition
if noRetryConditions != nil {
for _, noRetryCondition := range noRetryConditions {
if utils.Contains(noRetryCondition.Exception, err.ErrorName()) || utils.Contains(noRetryCondition.ErrorCode, err.ErrorCode()) {
return Bool(false)
}
}
}
if retryConditions != nil {
for _, retryCondition := range retryConditions {
if !utils.Contains(retryCondition.Exception, err.ErrorName()) && !utils.Contains(retryCondition.ErrorCode, err.ErrorCode()) {
continue
}
if IntValue(ctx.RetriesAttempted) > IntValue(retryCondition.MaxAttempts) {
return Bool(false)
}
return Bool(true)
}
}
}
return Bool(false)
}
func GetBackoffDelay(options *RetryOptions, ctx *RetryPolicyContext) *int64 {
if IntValue(ctx.RetriesAttempted) == 0 {
return Int64(0)
}
if err, ok := ctx.Error.(BaseError); ok {
if options != nil {
retryConditions := options.RetryCondition
if retryConditions != nil {
for _, retryCondition := range retryConditions {
if !utils.Contains(retryCondition.Exception, err.ErrorName()) && !utils.Contains(retryCondition.ErrorCode, err.ErrorCode()) {
continue
}
var maxDelay int64
if retryCondition.MaxDelayTimeMillis != nil {
maxDelay = Int64Value(retryCondition.MaxDelayTimeMillis)
} else {
maxDelay = DefaultMaxDelay.Milliseconds()
}
if err.RetryAfterTimeMillis() != nil {
return Int64(int64(math.Min(float64(Int64Value(err.RetryAfterTimeMillis())), float64(maxDelay))))
}
if retryCondition.Backoff == nil {
return Int64(DefaultMinDelay.Milliseconds())
}
delayTimeMillis := (*retryCondition.Backoff).GetDelayTimeMillis(ctx)
return Int64(int64(math.Min(float64(Int64Value(delayTimeMillis)), float64(maxDelay))))
}
}
}
}
return Int64(DefaultMinDelay.Milliseconds())
}
+536
View File
File diff suppressed because it is too large Load Diff
-860
View File
File diff suppressed because it is too large Load Diff
-547
View File
File diff suppressed because it is too large Load Diff
+75
View File
@@ -1,5 +1,12 @@
package tea
import (
"encoding/json"
"fmt"
"io"
"strings"
)
func String(a string) *string {
return &a
}
@@ -489,3 +496,71 @@ func BoolSliceValue(a []*bool) []bool {
}
return res
}
func TransInterfaceToBool(val interface{}) *bool {
if val == nil {
return nil
}
return Bool(val.(bool))
}
func TransInterfaceToInt(val interface{}) *int {
if val == nil {
return nil
}
return Int(val.(int))
}
func TransInterfaceToInt64(val interface{}) *int64 {
if val == nil {
return nil
}
return Int64(val.(int64))
}
func TransInterfaceToString(val interface{}) *string {
if val == nil {
return nil
}
return String(val.(string))
}
func ToInt(a *int32) *int {
return Int(int(Int32Value(a)))
}
func ToInt32(a *int) *int32 {
return Int32(int32(IntValue(a)))
}
func ToString(val interface{}) string {
return fmt.Sprintf("%v", val)
}
func ToObject(obj interface{}) map[string]interface{} {
result := make(map[string]interface{})
byt, _ := json.Marshal(obj)
err := json.Unmarshal(byt, &result)
if err != nil {
return nil
}
return result
}
func ToReader(obj interface{}) io.Reader {
switch obj.(type) {
case *string:
tmp := obj.(*string)
return strings.NewReader(StringValue(tmp))
case []byte:
return strings.NewReader(string(obj.([]byte)))
case io.Reader:
return obj.(io.Reader)
default:
panic("Invalid Body. Please set a valid Body.")
}
}
+85 -1
View File
@@ -1,9 +1,11 @@
package tea
import (
"io/ioutil"
"strings"
"testing"
"github.com/alibabacloud-go/tea/utils"
"github.com/alibabacloud-go/tea/v2/utils"
)
func Test_Trans(t *testing.T) {
@@ -161,3 +163,85 @@ func Test_Trans(t *testing.T) {
utils.AssertNil(t, Uint64Slice(nil))
utils.AssertNil(t, Uint64ValueSlice(nil))
}
func Test_TransInterfaceToInt(t *testing.T) {
a := TransInterfaceToInt(nil)
utils.AssertNil(t, a)
a = TransInterfaceToInt(10)
utils.AssertEqual(t, IntValue(a), 10)
}
func Test_TransInterfaceToInt64(t *testing.T) {
a := TransInterfaceToInt64(nil)
utils.AssertNil(t, a)
a = TransInterfaceToInt64(int64(10))
utils.AssertEqual(t, Int64Value(a), int64(10))
}
func Test_TransInterfaceToString(t *testing.T) {
a := TransInterfaceToString(nil)
utils.AssertNil(t, a)
a = TransInterfaceToString("10")
utils.AssertEqual(t, StringValue(a), "10")
}
func Test_TransInt32AndInt(t *testing.T) {
a := ToInt(Int32(10))
utils.AssertEqual(t, IntValue(a), 10)
b := ToInt32(a)
utils.AssertEqual(t, Int32Value(b), int32(10))
}
func Test_ToString(t *testing.T) {
str := ToString(10)
utils.AssertEqual(t, "10", str)
str = ToString("10")
utils.AssertEqual(t, "10", str)
}
func Test_ToObject(t *testing.T) {
str := "{sdsfdsd:"
result := ToObject(str)
utils.AssertNil(t, result)
input := map[string]string{
"name": "test",
}
result = ToObject(input)
utils.AssertEqual(t, "test", result["name"].(string))
}
func Test_ToReader(t *testing.T) {
str := "abc"
reader := ToReader(String(str))
byt, err := ioutil.ReadAll(reader)
utils.AssertNil(t, err)
utils.AssertEqual(t, "abc", string(byt))
read := strings.NewReader("bcd")
reader = ToReader(read)
byt, err = ioutil.ReadAll(reader)
utils.AssertNil(t, err)
utils.AssertEqual(t, "bcd", string(byt))
byts := []byte("cdf")
reader = ToReader(byts)
byt, err = ioutil.ReadAll(reader)
utils.AssertNil(t, err)
utils.AssertEqual(t, "cdf", string(byt))
num := 10
defer func() {
err := recover()
utils.AssertEqual(t, "Invalid Body. Please set a valid Body.", err.(string))
}()
reader = ToReader(num)
byt, err = ioutil.ReadAll(reader)
utils.AssertNil(t, err)
utils.AssertEqual(t, "", string(byt))
}
+13
View File
@@ -0,0 +1,13 @@
package utils
func Contains(s []*string, str *string) bool {
if s == nil {
return false
}
for _, v := range s {
if str != nil && v != nil && *v == *str {
return true
}
}
return false
}
+21
View File
@@ -0,0 +1,21 @@
package utils
import (
"testing"
)
func Test_Contains(t *testing.T) {
apple := "apple"
banana := "banana"
cherry := "cherry"
slice := []*string{&apple, &banana, &cherry, nil}
AssertEqual(t, true, Contains(slice, &banana))
toFind := "banana"
AssertEqual(t, true, Contains(slice, &toFind))
notFind := "notFind"
AssertEqual(t, false, Contains(slice, &notFind))
notFind = ""
AssertEqual(t, false, Contains(slice, &notFind))
AssertEqual(t, false, Contains(slice, nil))
AssertEqual(t, false, Contains(nil, nil))
}
-201
View File
@@ -1,201 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-12
View File
@@ -1,12 +0,0 @@
package debug
import (
"reflect"
"testing"
)
func assertEqual(t *testing.T, a, b interface{}) {
if !reflect.DeepEqual(a, b) {
t.Errorf("%v != %v", a, b)
}
}
-36
View File
@@ -1,36 +0,0 @@
package debug
import (
"fmt"
"os"
"strings"
)
type Debug func(format string, v ...interface{})
var hookGetEnv = func() string {
return os.Getenv("DEBUG")
}
var hookPrint = func(input string) {
fmt.Println(input)
}
func Init(flag string) Debug {
enable := false
env := hookGetEnv()
parts := strings.Split(env, ",")
for _, part := range parts {
if part == flag {
enable = true
break
}
}
return func(format string, v ...interface{}) {
if enable {
hookPrint(fmt.Sprintf(format, v...))
}
}
}

Some files were not shown because too many files have changed in this diff Show More