Documentation
¶
Index ¶
- func ReadError(r io.Reader) error
- func ReadResponse(r io.Reader, v interface{}) error
- func WriteError(w http.ResponseWriter, message string, code int) error
- func WriteResponse(w http.ResponseWriter, data interface{}, code int) error
- func WriteResponsePage(w http.ResponseWriter, data interface{}, pd *PageDetails, code int) error
- type Error
- type PageDetails
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadError ¶ added in v0.5.0
ReadError attempts to unmarshal JSON-encoded error details from the supplied reader. It returns nil if an error could not be parsed from the response, or if the parsed error was nil.
func ReadResponse ¶
ReadResponse reads a JSON response, and unmarshals the supplied data.
func WriteError ¶
func WriteError(w http.ResponseWriter, message string, code int) error
WriteError writes a status code and JSON response containing the supplied error message and status code to w.
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, data interface{}, code int) error
WriteResponse writes a status code and JSON response containing data to w.
func WriteResponsePage ¶ added in v0.2.0
func WriteResponsePage(w http.ResponseWriter, data interface{}, pd *PageDetails, code int) error
WriteResponsePage writes a status code and JSON response containing data and pd to w.
Types ¶
type PageDetails ¶ added in v0.2.0
type PageDetails struct {
Prev string `json:"prev,omitempty"`
Next string `json:"next,omitempty"`
TotalSize int `json:"totalSize,omitempty"`
}
PageDetails specifies paging information.
func ReadResponsePage ¶ added in v0.2.0
func ReadResponsePage(r io.Reader, v interface{}) (pd *PageDetails, err error)
ReadResponsePage reads a paged JSON response, and unmarshals the supplied data.
type Response ¶
type Response struct {
Data interface{} `json:"data,omitempty"`
Page *PageDetails `json:"page,omitempty"`
Error *Error `json:"error,omitempty"`
}
Response is the top level container of all of our REST API responses.