Back to

Package http

Latest Go to latest

The highest tagged major version is .

Published: Sep 17, 2020 | License: MIT | Module:


Package http implements the basic pace microservice handlers and a standard microservice server configured via environment variables.



var (
	ErrNotFound       = errors.New("not found")
	ErrInvalidRequest = errors.New("request is invalid")

All exported package errors.

func ContextTransfer

func ContextTransfer(ctx, targetCtx context.Context) context.Context

ContextTransfer copies a request representation from one context to another.

func Environment

func Environment() string

Environment returns the name of the current server environment

func GetUserAgentFromContext

func GetUserAgentFromContext(ctx context.Context) (string, error)

GetUserAgentFromContext returns the User-Agent header value from the request that is stored in the context. Returns ErrNotFound if the context does not have a request.

func GetXForwardedForHeaderFromContext

func GetXForwardedForHeaderFromContext(ctx context.Context) (string, error)

GetXForwardedForHeaderFromContext returns the X-Forwarded-For header value that would express that you forwarded the request that is stored in the context.

If the remote address of the request is then the value is that remote ip without the port. If the request already includes this header, the remote ip is appended to the value of that header. For example if the request on top of the remote ip also includes the header "X-Forwarded-For:" then the resulting value is ",".

Returns ErrNotFound if the context does not have a request. Returns ErrInvalidRequest if the request in the context is malformed, for example because it does not have a remote address, which should never happen.

func JsonApiErrorWriterMiddleware

func JsonApiErrorWriterMiddleware(next http.Handler) http.Handler

JsonApiErrorWriterMiddleware is a middleware that wraps http.ResponseWriter such that it forces responses with status codes 4xx/5xx to have Content-Type: application/vnd.api+json

func RequestInContextMiddleware

func RequestInContextMiddleware(next http.Handler) http.Handler

RequestInContextMiddleware stores a representation of the request in the context of said request. Some information of that request can then be accessed through the context using functions of this package.

func Router

func Router() *mux.Router

Router returns the default microservice endpoints for health, metrics and debugging

func Server

func Server(handler http.Handler) *http.Server

Server returns a http.Server configured using environment variables, following

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

Jump to identifier

Keyboard shortcuts

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