response

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSONEncoder

func NewJSONEncoder() middleware.Middleware

NewJSONEncoder creates a new response middleware

func WithError

func WithError(ctx context.Context, err Error)

WithError add an Error struct to the given context

func WithPayload

func WithPayload(ctx context.Context, payload interface{})

WithPayload adds payload to the given context

Types

type Buffer

type Buffer struct {
	Response http.ResponseWriter
	Status   int
	Body     *bytes.Buffer
}

Buffer implements ResponseWriter interface and can be used to collect the response body in a middleware handlers.

func NewBuffer

func NewBuffer(w http.ResponseWriter) *Buffer

NewBuffer create a new response buffer

func (*Buffer) Flush

func (w *Buffer) Flush()

Flush implements the Flusher interface

func (*Buffer) Header

func (w *Buffer) Header() http.Header

Header returns the response header handle.

func (*Buffer) Write

func (w *Buffer) Write(buf []byte) (int, error)

Write buffers the response.

func (*Buffer) WriteHeader

func (w *Buffer) WriteHeader(status int)

WriteHeader stores the status code

type Error

type Error struct {
	Code    int    `json:"code"`
	Error   error  `json:"error"`
	Message string `json:"message"`
}

Error is a struct to store a JSON error representation

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of Marshaler interface for Error

Jump to

Keyboard shortcuts

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