Skip to content

Commit

Permalink
Make some edits
Browse files Browse the repository at this point in the history
  • Loading branch information
bozd4g committed Oct 4, 2020
1 parent a296170 commit ace78a8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {

// or
var todo2 Todo
err = httpClient.Do(request).To(&todo2)
response, err = httpClient.Do(request).To(&todo2)
if err != nil {
fmt.Println(todo.Title) // Lorem ipsum dolor sit amet
} else {
Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ func (h httpClient) Do(request *http.Request) ServiceResponse {
}

// To func returns converts string to struct
func (s ServiceResponse) To(value interface{}) error {
func (s ServiceResponse) To(value interface{}) (ServiceResponse, error) {
if s.Data != "" {
return json.Unmarshal([]byte(s.Data), &value)
return s, json.Unmarshal([]byte(s.Data), &value)
}

return errors.New("response body cannot be empty")
return s, errors.New("response body cannot be empty")
}
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGetRequestWithTo(t *testing.T) {

var got Todo
want := 10
err := httpClient.Do(request).To(&got)
_, err := httpClient.Do(request).To(&got)
if err != nil {
t.Error(err.Error())
}
Expand Down

0 comments on commit ace78a8

Please sign in to comment.