Documentation ¶
Overview ¶
Package response implements reflection-based net/http response encoder.
Index ¶
- Variables
- func EncoderMiddleware(handler http.Handler) http.Handler
- func ValidatorMiddleware(factory rest.ResponseValidatorFactory) func(http.Handler) http.Handler
- type EmbeddedSetter
- type Encoder
- func (h *Encoder) MakeOutput(w http.ResponseWriter, ht rest.HandlerTrait) interface{}
- func (h *Encoder) SetupOutput(output interface{}, ht *rest.HandlerTrait)
- func (h *Encoder) WriteErrResponse(w http.ResponseWriter, r *http.Request, statusCode int, response interface{})
- func (h *Encoder) WriteSuccessfulResponse(w http.ResponseWriter, r *http.Request, output interface{}, ...)
- type Setter
Constants ¶
This section is empty.
Variables ¶
var DefaultErrorResponseContentType = "application/json"
DefaultErrorResponseContentType is a package-level variable set to default error response content type.
var DefaultSuccessResponseContentType = "application/json"
DefaultSuccessResponseContentType is a package-level variable set to default success response content type.
Functions ¶
func EncoderMiddleware ¶
EncoderMiddleware instruments qualifying http.Handler with Encoder.
func ValidatorMiddleware ¶
ValidatorMiddleware sets up response validator in suitable handlers.
Types ¶
type EmbeddedSetter ¶ added in v0.2.61
type EmbeddedSetter struct {
// contains filtered or unexported fields
}
EmbeddedSetter can capture http.ResponseWriter in your output structure.
func (*EmbeddedSetter) ResponseWriter ¶ added in v0.2.61
func (e *EmbeddedSetter) ResponseWriter() http.ResponseWriter
ResponseWriter is an accessor.
func (*EmbeddedSetter) SetResponseWriter ¶ added in v0.2.61
func (e *EmbeddedSetter) SetResponseWriter(rw http.ResponseWriter)
SetResponseWriter implements Setter.
type Encoder ¶
type Encoder struct { JSONWriter func(v interface{}) // contains filtered or unexported fields }
Encoder prepares and writes http response.
func (*Encoder) MakeOutput ¶
func (h *Encoder) MakeOutput(w http.ResponseWriter, ht rest.HandlerTrait) interface{}
MakeOutput instantiates a value for use case output port.
func (*Encoder) SetupOutput ¶
func (h *Encoder) SetupOutput(output interface{}, ht *rest.HandlerTrait)
SetupOutput configures encoder with and instance of use case output.
func (*Encoder) WriteErrResponse ¶
func (h *Encoder) WriteErrResponse(w http.ResponseWriter, r *http.Request, statusCode int, response interface{})
WriteErrResponse encodes and writes error to response.
func (*Encoder) WriteSuccessfulResponse ¶
func (h *Encoder) WriteSuccessfulResponse( w http.ResponseWriter, r *http.Request, output interface{}, ht rest.HandlerTrait, )
WriteSuccessfulResponse encodes and writes successful output of use case interactor to http response.
type Setter ¶ added in v0.2.61
type Setter interface {
SetResponseWriter(rw http.ResponseWriter)
}
Setter captures original http.ResponseWriter.
Implement this interface on a pointer to your output structure to get access to http.ResponseWriter.