middleware

package
v0.0.0-...-a69ed84 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PromMetrics

func PromMetrics(serviceName string, buckets []float64) func(next http.Handler) http.Handler

PromMetrics returns middleware with Prometheus metrics.

func RenderJSON

func RenderJSON(next http.Handler) http.Handler

RenderJSON middleware is used to inject response object in context and later render it as JSON.

func ZapLogger

func ZapLogger(logger *zap.Logger) func(next http.Handler) http.Handler

ZapLogger is Chi middleware for logging requests using Zap logger.

Types

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response ...

func ResponseFromContext

func ResponseFromContext(ctx context.Context) *Response

ResponseFromContext returns response from context.

func (*Response) AddError

func (r *Response) AddError(err string) *Response

AddError adds error to response.

func (*Response) AddHeader

func (r *Response) AddHeader(key, value string) *Response

AddHeader ads headers to response.

func (*Response) SetHeader

func (r *Response) SetHeader(key, value string) *Response

SetHeader sets header to response.

func (*Response) SetPayload

func (r *Response) SetPayload(payload interface{}) *Response

SetPayload sets payload to response.

func (*Response) SetStatus

func (r *Response) SetStatus(statusCode int) *Response

SetStatus sets status code to response. If status code is not set if will default to http.StatusOK.

func (*Response) SetStatusAccepted

func (r *Response) SetStatusAccepted() *Response

SetStatusAccepted sets status code to http.StatusAccepted.

func (*Response) SetStatusBadRequest

func (r *Response) SetStatusBadRequest(err string) *Response

SetStatusBadRequest sets status code to http.StatusBadRequest.

func (*Response) SetStatusForbidden

func (r *Response) SetStatusForbidden(err string) *Response

SetStatusForbidden sets status code to http.StatusForbidden.

func (*Response) SetStatusInternalServerError

func (r *Response) SetStatusInternalServerError(err string) *Response

SetStatusInternalServerError sets status code to http.StatusInternalServerError.

func (*Response) SetStatusNotFound

func (r *Response) SetStatusNotFound(err string) *Response

SetStatusNotFound sets status code to http.StatusNotFound.

Jump to

Keyboard shortcuts

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