Back to godoc.org

Package middleware

v0.0.0-...-347c1b2
Latest Go to latest

The highest tagged major version is .

Published: Sep 10, 2020 | License: MIT | Module: github.com/acim/go-rest-server

Index

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.

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier