http

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package http implements a core suite of HTTP functions for use inside Moov. These packages are designed to be used in production to provide insight without an excessive performance tradeoff.

This package implements several opininated response functions (See Problem, InternalError) and stateless CORS handling under our load balancing setup. They may not work for you.

This package also implements a wrapper around http.ResponseWriter to log X-Request-ID, timing and the resulting status code.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoUserID is returned when no x-user-id header was found
	ErrNoUserID = errors.New("no X-User-Id header provided")
)

Functions

func AddCORSHandler

func AddCORSHandler(r *mux.Router)

AddCORSHandler captures Corss Origin Resource Sharing (CORS) requests by looking at all OPTIONS requests for the Origin header, parsing that and responding back with the other Access-Control-Allow-* headers.

Docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

func GetRequestID

func GetRequestID(r *http.Request) string

GetRequestID returns the Moov header value for request IDs

func GetUserID

func GetUserID(r *http.Request) string

GetUserID returns the Moov userId from HTTP headers

func InternalError

func InternalError(w http.ResponseWriter, err error) string

InternalError writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.

Returned is the calling file and line number: server.go:33

func Problem

func Problem(w http.ResponseWriter, err error)

Problem writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.

func SetAccessControlAllowHeaders

func SetAccessControlAllowHeaders(w http.ResponseWriter, origin string)

SetAccessControlAllowHeaders writes Access-Control-Allow-* headers to a response to allow for further CORS-allowed requests.

Types

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter implements Go's standard library http.ResponseWriter to complete HTTP requests

func EnsureHeaders

EnsureHeaders wraps the http.ResponseWriter but also checks Moov specific headers.

X-User-Id is required, and requests without one will be completed with a 403 forbidden. No lookup is done to ensure the value exists and is valid for a Moov user.

X-Request-Id is optional, but if used we will emit a log line with that request fulfillment timing and the status code.

X-Idempotency-Key is optional, but recommended to ensure requests only execute once. Clients are assumed to resend requests many times with the same key. We just need to reply back "already done".

func Wrap

Wrap returns a ResponseWriter usable by applications. No parts of the Request are inspected or ResponseWriter modified.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(code int)

WriteHeader sends an HTTP response header with the provided status code, records response duration, and optionally records the HTTP metadata in a go-kit log.Logger

Directories

Path Synopsis
Package bind returns well known HTTP local bind addresses for Moov services.
Package bind returns well known HTTP local bind addresses for Moov services.

Jump to

Keyboard shortcuts

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