diff --git a/.gitignore b/.gitignore index acaf5a54..5e6ae9d3 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ java/.settings/ java/bin/ java/.classpath .vscode/ -cc/*.o \ No newline at end of file +cc/*.o +*.sum \ No newline at end of file diff --git a/Teafile b/Teafile index 063d97c7..8fd3a4a8 100644 --- a/Teafile +++ b/Teafile @@ -4,7 +4,7 @@ "version": "0.1.5", "main": "./main.tea", "releases": { - "go": "github.com/aliyun/tea-util/golang/service:v0.0.5", + "go": "github.com/aliyun/tea-util/golang/service:v0.0.6", "ts": "@alicloud/tea-util:^1.1.0", "csharp": "AlibabaCloud.TeaUtil:0.0.4", "java": "com.aliyun:tea-util:0.1.5" diff --git a/golang/ChangeLog.txt b/golang/ChangeLog.txt index 764f975a..db94c915 100644 --- a/golang/ChangeLog.txt +++ b/golang/ChangeLog.txt @@ -1,3 +1,6 @@ +2020-03-04 Version: v0.0.6 +- Add Set Func for RuntimeOptions. + 2020-03-02 Version: v0.0.5 - Modify StringifyMapValue. diff --git a/golang/go.mod b/golang/go.mod index 546deec1..09362ff6 100644 --- a/golang/go.mod +++ b/golang/go.mod @@ -1 +1,10 @@ module github.com/aliyun/tea-util/golang + +require ( + github.com/alibabacloud-go/tea v0.0.7 + golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 // indirect + golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect + golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect + golang.org/x/text v0.3.2 // indirect + golang.org/x/tools v0.0.0-20200303225724-c5a141475315 // indirect +) diff --git a/golang/service/service.go b/golang/service/service.go index 1cbb0d90..03a1b48a 100644 --- a/golang/service/service.go +++ b/golang/service/service.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/alibabacloud-go/tea/tea" "github.com/aliyun/tea-util/golang/utils" ) @@ -34,6 +35,84 @@ type RuntimeOptions struct { Socks5NetWork *string `json:"socks5NetWork" xml:"socks5NetWork"` } +func (s RuntimeOptions) String() string { + return tea.Prettify(s) +} + +func (s RuntimeOptions) GoString() string { + return s.String() +} + +func (s *RuntimeOptions) SetAutoretry(v bool) *RuntimeOptions { + s.Autoretry = &v + return s +} + +func (s *RuntimeOptions) SetIgnoreSSL(v bool) *RuntimeOptions { + s.IgnoreSSL = &v + return s +} + +func (s *RuntimeOptions) SetMaxAttempts(v int) *RuntimeOptions { + s.MaxAttempts = &v + return s +} + +func (s *RuntimeOptions) SetBackoffPolicy(v string) *RuntimeOptions { + s.BackoffPolicy = &v + return s +} + +func (s *RuntimeOptions) SetBackoffPeriod(v int) *RuntimeOptions { + s.BackoffPeriod = &v + return s +} + +func (s *RuntimeOptions) SetReadTimeout(v int) *RuntimeOptions { + s.ReadTimeout = &v + return s +} + +func (s *RuntimeOptions) SetConnectTimeout(v int) *RuntimeOptions { + s.ConnectTimeout = &v + return s +} + +func (s *RuntimeOptions) SetHttpProxy(v string) *RuntimeOptions { + s.HttpProxy = &v + return s +} + +func (s *RuntimeOptions) SetHttpsProxy(v string) *RuntimeOptions { + s.HttpsProxy = &v + return s +} + +func (s *RuntimeOptions) SetNoProxy(v string) *RuntimeOptions { + s.NoProxy = &v + return s +} + +func (s *RuntimeOptions) SetMaxIdleConns(v int) *RuntimeOptions { + s.MaxIdleConns = &v + return s +} + +func (s *RuntimeOptions) SetLocalAddr(v string) *RuntimeOptions { + s.LocalAddr = &v + return s +} + +func (s *RuntimeOptions) SetSocks5Proxy(v string) *RuntimeOptions { + s.Socks5Proxy = &v + return s +} + +func (s *RuntimeOptions) SetSocks5NetWork(v string) *RuntimeOptions { + s.Socks5NetWork = &v + return s +} + func ReadAsString(body io.Reader) (string, error) { byt, err := ioutil.ReadAll(body) if err != nil { diff --git a/golang/service/service_test.go b/golang/service/service_test.go index 6386902e..5be518ca 100644 --- a/golang/service/service_test.go +++ b/golang/service/service_test.go @@ -4,9 +4,42 @@ import ( "strings" "testing" + "github.com/alibabacloud-go/tea/tea" "github.com/aliyun/tea-util/golang/utils" ) +func Test_SetFunc(t *testing.T) { + runtime := new(RuntimeOptions).SetAutoretry(true). + SetBackoffPeriod(10). + SetBackoffPolicy("no"). + SetConnectTimeout(100). + SetHttpProxy("httpproxy"). + SetHttpsProxy("httpsproxy"). + SetIgnoreSSL(true). + SetLocalAddr("localaddr"). + SetMaxAttempts(3). + SetMaxIdleConns(5). + SetNoProxy("noproxy"). + SetReadTimeout(50). + SetSocks5NetWork("tcp"). + SetSocks5Proxy("sock5proxy") + utils.AssertEqual(t, true, tea.BoolValue(runtime.Autoretry)) + utils.AssertEqual(t, true, tea.BoolValue(runtime.IgnoreSSL)) + utils.AssertEqual(t, 10, tea.IntValue(runtime.BackoffPeriod)) + utils.AssertEqual(t, 100, tea.IntValue(runtime.ConnectTimeout)) + utils.AssertEqual(t, 50, tea.IntValue(runtime.ReadTimeout)) + utils.AssertEqual(t, 3, tea.IntValue(runtime.MaxAttempts)) + utils.AssertEqual(t, 5, tea.IntValue(runtime.MaxIdleConns)) + utils.AssertEqual(t, "no", tea.StringValue(runtime.BackoffPolicy)) + utils.AssertEqual(t, "httpproxy", tea.StringValue(runtime.HttpProxy)) + utils.AssertEqual(t, "httpsproxy", tea.StringValue(runtime.HttpsProxy)) + utils.AssertEqual(t, "localaddr", tea.StringValue(runtime.LocalAddr)) + utils.AssertEqual(t, "noproxy", tea.StringValue(runtime.NoProxy)) + utils.AssertEqual(t, "tcp", tea.StringValue(runtime.Socks5NetWork)) + utils.AssertEqual(t, "sock5proxy", tea.StringValue(runtime.Socks5Proxy)) + runtime.GoString() +} + func Test_ReadAsString(t *testing.T) { str, err := ReadAsString(strings.NewReader("common")) utils.AssertNil(t, err)