Documentation ¶
Index ¶
- Constants
- func CodeAndMessageFrom(err error) (int, interface{})
- func EncodeError(l logger, codeAndMessageFrom func(err error) (int, interface{})) httptransport.ErrorEncoder
- func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
- func EncodeResponseAsIs(_ context.Context, w http.ResponseWriter, response interface{}) error
- type BoolResultResponse
- type ErrorResponse
- type ListMeta
- type ListResponse
- type Response
Constants ¶
View Source
const ( ContentTypeHeader = "Content-Type" ContentType = "application/json; charset=utf-8" )
Predefined http encoder content type
Variables ¶
This section is empty.
Functions ¶
func CodeAndMessageFrom ¶
CodeAndMessageFrom helper
func EncodeError ¶
func EncodeError(l logger, codeAndMessageFrom func(err error) (int, interface{})) httptransport.ErrorEncoder
EncodeError ...
func EncodeResponse ¶
func EncodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
EncodeResponse is the common method to encode all response types to the client. I chose to do it this way because, since we're using JSON, there's no reason to provide anything more specific. It's certainly possible to specialize on a per-response (per-method) basis.
func EncodeResponseAsIs ¶
func EncodeResponseAsIs(_ context.Context, w http.ResponseWriter, response interface{}) error
EncodeResponseAsIs is almost the same as EncodeResponse, but it doesn't wrap the response in a Response struct. This is useful for endpoints that return a single value, like a string or a number.
Types ¶
type BoolResultResponse ¶
type BoolResultResponse struct {
Result bool `json:"result"`
}
BoolResultResponse struct
type ErrorResponse ¶
type ErrorResponse struct { Code int `json:"code"` Err string `json:"error"` Message string `json:"message,omitempty"` Details interface{} `json:"details,omitempty"` RequestID string `json:"request_id,omitempty"` }
Error represents an error response
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
Error implements the error interface
type ListResponse ¶
type ListResponse struct { Data interface{} `json:"data,omitempty"` Meta *ListMeta `json:"meta,omitempty"` }
ListResponse struct
Click to show internal directories.
Click to hide internal directories.