-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce response decoder interface
- Loading branch information
Showing
3 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sling | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
// ResponseDecoder decodes http responses into struct values. | ||
type ResponseDecoder interface { | ||
Decode(resp *http.Response, v interface{}) error | ||
} | ||
|
||
// jsonDecoder decodes http response JSON into a JSON-tagged struct value. | ||
type jsonDecoder struct { | ||
} | ||
|
||
// Decode the Response Body into the value pointed to by v. | ||
// Caller must provide a non-nil v and close the resp.Body. | ||
func (d jsonDecoder) Decode(resp *http.Response, v interface{}) error { | ||
return json.NewDecoder(resp.Body).Decode(v) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters