Skip to content

Commit

Permalink
support ignore tag
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Jan 5, 2021
1 parent fa78087 commit 2a316b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ func structToMap(dataValue reflect.Value) map[string]interface{} {
if !fieldValue.IsValid() || fieldValue.IsNil() {
continue
}
if field.Type.Kind().String() == "struct" {
if field.Type.String() == "io.Reader" || field.Type.String() == "io.Writer" {
continue
} else if field.Type.Kind().String() == "struct" {
out[name] = structToMap(fieldValue)
} else if field.Type.Kind().String() == "ptr" &&
field.Type.Elem().Kind().String() == "struct" {
Expand Down
8 changes: 7 additions & 1 deletion tea/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"io"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -240,6 +241,8 @@ type Test struct {
List []string `json:"List,omitempty"`
CastList []CastError `json:"CastList,omitempty"`
CastListPtr []*CastError `json:"CastListPtr,omitempty"`
Reader io.Reader
Inter interface{}
}

func TestToMap(t *testing.T) {
Expand Down Expand Up @@ -273,9 +276,12 @@ func TestToMap(t *testing.T) {
Message: String("CastList"),
},
},
Reader: strings.NewReader(""),
Inter: 10,
}
result = ToMap(valid)
utils.AssertEqual(t, "tea", result["Msg"])
utils.AssertNil(t, result["Reader"])
utils.AssertEqual(t, map[string]interface{}{"Message": "message"}, result["Cast"])
utils.AssertEqual(t, []interface{}{"test", ""}, result["ListPtr"])
utils.AssertEqual(t, []interface{}{"list"}, result["List"])
Expand Down Expand Up @@ -456,7 +462,7 @@ func Test_DoRequest(t *testing.T) {
runtimeObj["cert"] = cert
runtimeObj["ca"] = "private ca"
runtimeObj["socks5Proxy"] = "socks5://someuser:[email protected]"
resp, err = DoRequest(request, runtimeObj)
_, err = DoRequest(request, runtimeObj)
utils.AssertNotNil(t, err)

runtimeObj["ca"] = ca
Expand Down

0 comments on commit 2a316b9

Please sign in to comment.