response

package
v0.2.70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 14 Imported by: 10

Documentation

Overview

Package response implements reflection-based net/http response encoder.

Index

Constants

This section is empty.

Variables

View Source
var DefaultErrorResponseContentType = "application/json"

DefaultErrorResponseContentType is a package-level variable set to default error response content type.

View Source
var DefaultSuccessResponseContentType = "application/json"

DefaultSuccessResponseContentType is a package-level variable set to default success response content type.

Functions

func EncoderMiddleware

func EncoderMiddleware(handler http.Handler) http.Handler

EncoderMiddleware instruments qualifying http.Handler with Encoder.

func ValidatorMiddleware

func ValidatorMiddleware(factory rest.ResponseValidatorFactory) func(http.Handler) http.Handler

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.

Directories

Path Synopsis
Package gzip provides http compression support.
Package gzip provides http compression support.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL