Skip to content

Commit

Permalink
add setfunc
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Mar 4, 2020
1 parent 69fd261 commit e369c78
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ java/.settings/
java/bin/
java/.classpath
.vscode/
cc/*.o
cc/*.o
*.sum
2 changes: 1 addition & 1 deletion Teafile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions golang/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
9 changes: 9 additions & 0 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
79 changes: 79 additions & 0 deletions golang/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/alibabacloud-go/tea/tea"
"github.com/aliyun/tea-util/golang/utils"
)

Expand All @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions golang/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e369c78

Please sign in to comment.