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 ¶
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
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.
Types ¶
type BoolResultResponse ¶
type BoolResultResponse struct {
Result bool `json:"result"`
}
BoolResultResponse struct
type ErrorResponse ¶
type ErrorResponse struct { Code int `json:"code"` Error 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 NewErrorResponse ¶
func NewErrorResponse(code int, err error, details interface{}, reqID string) ErrorResponse
NewErrorResponse creates a new ErrorResponse payload
type ListResponse ¶
type ListResponse struct { Data interface{} `json:"data,omitempty"` Meta ListMeta `json:"meta,omitempty"` }
ListResponse struct