Documentation
¶
Index ¶
- func ErrorResponseEncoder(encoder kithttp.EncodeResponseFunc, errorEncoder EncodeErrorResponseFunc) kithttp.EncodeResponseFunc
- func JSONResponseEncoder(ctx context.Context, w http.ResponseWriter, resp interface{}) error
- func NewDefaultJSONProblemErrorEncoder() kithttp.ErrorEncoder
- func NewDefaultXMLProblemErrorEncoder() kithttp.ErrorEncoder
- func NewJSONProblemErrorEncoder(problemConverter ProblemConverter) kithttp.ErrorEncoder
- func NewXMLProblemErrorEncoder(problemConverter ProblemConverter) kithttp.ErrorEncoder
- func NopResponseEncoder(_ context.Context, _ http.ResponseWriter, _ interface{}) error
- func ServerOptions(options []http.ServerOption) http.ServerOption
- func StatusCodeResponseEncoder(code int) kithttp.EncodeResponseFunc
- func WithStatusCode(resp interface{}, code int) interface{}
- type EncodeErrorResponseFunc
- func NewDefaultJSONProblemErrorResponseEncoder() EncodeErrorResponseFunc
- func NewDefaultXMLProblemErrorResponseEncoder() EncodeErrorResponseFunc
- func NewJSONProblemErrorResponseEncoder(problemConverter ProblemConverter) EncodeErrorResponseFunc
- func NewXMLProblemErrorResponseEncoder(problemConverter ProblemConverter) EncodeErrorResponseFunc
- type ProblemConverter
- type ServerFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorResponseEncoder ¶
func ErrorResponseEncoder( encoder kithttp.EncodeResponseFunc, errorEncoder EncodeErrorResponseFunc, ) kithttp.EncodeResponseFunc
ErrorResponseEncoder encodes the passed response object to the HTTP response writer in JSON format.
func JSONResponseEncoder ¶
func JSONResponseEncoder(ctx context.Context, w http.ResponseWriter, resp interface{}) error
JSONResponseEncoder encodes the passed response object to the HTTP response writer in JSON format.
func NewDefaultJSONProblemErrorEncoder ¶ added in v0.5.0
func NewDefaultJSONProblemErrorEncoder() kithttp.ErrorEncoder
NewDefaultJSONProblemErrorEncoder returns an error encoder that encodes errors following the RFC-7807 (Problem Details) standard (in JSON format).
See details at https://tools.ietf.org/html/rfc7807
The returned encoder encodes every error as 500 Internal Server Error.
func NewDefaultXMLProblemErrorEncoder ¶ added in v0.5.0
func NewDefaultXMLProblemErrorEncoder() kithttp.ErrorEncoder
NewDefaultXMLProblemErrorEncoder returns an error encoder that encodes errors following the RFC-7807 (Problem Details) standard (in XML format).
See details at https://tools.ietf.org/html/rfc7807
The returned encoder encodes every error as 500 Internal Server Error.
func NewJSONProblemErrorEncoder ¶ added in v0.5.0
func NewJSONProblemErrorEncoder(problemConverter ProblemConverter) kithttp.ErrorEncoder
NewJSONProblemErrorEncoder returns an error encoder that encodes errors following the RFC-7807 (Problem Details) standard (in JSON format).
See details at https://tools.ietf.org/html/rfc7807
func NewXMLProblemErrorEncoder ¶ added in v0.5.0
func NewXMLProblemErrorEncoder(problemConverter ProblemConverter) kithttp.ErrorEncoder
NewXMLProblemErrorEncoder returns an error encoder that encodes errors following the RFC-7807 (Problem Details) standard (in XML format).
See details at https://tools.ietf.org/html/rfc7807
func NopResponseEncoder ¶
func NopResponseEncoder(_ context.Context, _ http.ResponseWriter, _ interface{}) error
NopResponseEncoder can be used for operations without output parameters. It returns 200 OK status code without a response body.
func ServerOptions ¶ added in v0.2.0
func ServerOptions(options []http.ServerOption) http.ServerOption
ServerOptions collects a list of ServerOptions into a single option. Useful to avoid variadic hells when passing lists of options around.
func StatusCodeResponseEncoder ¶
func StatusCodeResponseEncoder(code int) kithttp.EncodeResponseFunc
StatusCodeResponseEncoder can be used for operations without output parameters. It returns status code given without a response body.
func WithStatusCode ¶ added in v0.3.0
func WithStatusCode(resp interface{}, code int) interface{}
WithStatusCode wraps a response and implements the kithttp.StatusCoder interface. It allows passing a status code to kithttp.EncodeJSONResponse.
Note: it only works with JSON marshaler.
Types ¶
type EncodeErrorResponseFunc ¶
EncodeErrorResponseFunc encodes the passed error to the HTTP response writer. It's designed to be used in HTTP servers, for server-side endpoints. An EncodeErrorResponseFunc is supposed to return an error with the proper HTTP status code.
func NewDefaultJSONProblemErrorResponseEncoder ¶ added in v0.6.0
func NewDefaultJSONProblemErrorResponseEncoder() EncodeErrorResponseFunc
NewDefaultJSONProblemErrorResponseEncoder returns an error response encoder that encodes errors following the RFC-7807 (Problem Details) standard (in JSON format).
See details at https://tools.ietf.org/html/rfc7807
The returned encoder encodes every error as 500 Internal Server Error.
func NewDefaultXMLProblemErrorResponseEncoder ¶ added in v0.6.0
func NewDefaultXMLProblemErrorResponseEncoder() EncodeErrorResponseFunc
NewDefaultXMLProblemErrorResponseEncoder returns an error response encoder that encodes errors following the RFC-7807 (Problem Details) standard (in XML format).
See details at https://tools.ietf.org/html/rfc7807
The returned encoder encodes every error as 500 Internal Server Error.
func NewJSONProblemErrorResponseEncoder ¶ added in v0.6.0
func NewJSONProblemErrorResponseEncoder(problemConverter ProblemConverter) EncodeErrorResponseFunc
NewJSONProblemErrorResponseEncoder returns an error response encoder that encodes errors following the RFC-7807 (Problem Details) standard (in JSON format).
See details at https://tools.ietf.org/html/rfc7807
func NewXMLProblemErrorResponseEncoder ¶ added in v0.6.0
func NewXMLProblemErrorResponseEncoder(problemConverter ProblemConverter) EncodeErrorResponseFunc
NewXMLProblemErrorResponseEncoder returns an error response encoder that encodes errors following the RFC-7807 (Problem Details) standard (in XML format).
See details at https://tools.ietf.org/html/rfc7807
type ProblemConverter ¶ added in v0.6.0
type ProblemConverter interface { // NewProblem creates a new RFC-7807 Problem from an error. NewProblem(ctx context.Context, err error) interface{} }
ProblemConverter creates a new RFC-7807 Problem from an error.
type ServerFactory ¶
type ServerFactory interface { // NewServer constructs a new server, which implements http.Handler and wraps the provided endpoint. NewServer( e endpoint.Endpoint, dec http.DecodeRequestFunc, enc http.EncodeResponseFunc, options ...http.ServerOption, ) *http.Server }
ServerFactory constructs a new server, which implements http.Handler and wraps the provided endpoint.
func NewServerFactory ¶
func NewServerFactory(options ...http.ServerOption) ServerFactory
NewServerFactory returns a new ServerFactory.