feat: simplify httpc (#1748)

* feat: simplify httpc

* chore: fix lint errors

* chore: fix log url issue

* chore: fix log url issue

* refactor: handle resp & err in ResponseHandler

* chore: remove unnecessary var names in return clause
This commit is contained in:
Kevin Wan
2022-04-03 14:32:27 +08:00
committed by GitHub
parent e0fa8d820d
commit 78ea0769fd
8 changed files with 91 additions and 86 deletions

View File

@@ -20,7 +20,9 @@ func TestParse(t *testing.T) {
w.Write([]byte(`{"name":"kevin","value":100}`))
}))
defer svr.Close()
resp, err := Get("foo", svr.URL)
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
assert.Nil(t, err)
resp, err := DoRequest(req)
assert.Nil(t, err)
assert.Nil(t, Parse(resp, &val))
assert.Equal(t, "bar", val.Foo)
@@ -37,7 +39,9 @@ func TestParseHeaderError(t *testing.T) {
w.Header().Set(contentType, applicationJson)
}))
defer svr.Close()
resp, err := Get("foo", svr.URL)
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
assert.Nil(t, err)
resp, err := DoRequest(req)
assert.Nil(t, err)
assert.NotNil(t, Parse(resp, &val))
}
@@ -51,7 +55,9 @@ func TestParseNoBody(t *testing.T) {
w.Header().Set(contentType, applicationJson)
}))
defer svr.Close()
resp, err := Get("foo", svr.URL)
req, err := http.NewRequest(http.MethodGet, svr.URL, nil)
assert.Nil(t, err)
resp, err := DoRequest(req)
assert.Nil(t, err)
assert.Nil(t, Parse(resp, &val))
assert.Equal(t, "bar", val.Foo)