handlerutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestId

func RequestId(ctx context.Context) string

RequestId returns the id of the current request set in context, or an empty string.

func WithRequestId

func WithRequestId(handlerFunc http.HandlerFunc) http.HandlerFunc

WithRequestId is an middleware that assigns request id for each incoming request. The assigned id can be retrieved downstream by

requestId := RequestId(ctx)

func WriteErrorToBody

func WriteErrorToBody(rw http.ResponseWriter, err error)

WriteErrorToBody writes the given error in JSON format to HTTP response body.

Types

type ErrorView

type ErrorView struct {
	Status      int    `json:"status"`
	Error       string `json:"error"`
	Description string `json:"error_description"`
	Cause       error  `json:"-"`
}

ErrorView contains the data necessary to render errors.

type RequestIdKey

type RequestIdKey struct{}

Context key for request id

Jump to

Keyboard shortcuts

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