middleware

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const RequestIDHeader = "X-Request-ID"

RequestIDHeader is the response header name for request IDs.

Variables

View Source
var (
	AccessControlAllowMethods = strings.Join([]string{
		"DELETE",
		"GET",
		"HEAD",
		"OPTIONS",
		"PATCH",
		"POST",
		"PUT",
	}, corsSep)
	AccessControlAllowHeaders = strings.Join([]string{
		"Accept",
		"Authorization",
		"Cache-Control",
		"Content-Length",
		"Content-Type",
		"DNT",
		"If-Modified-Since",
		"Origin",
		"Range",
		"User-Agent",
		"X-Requested-With",
	}, corsSep)
	AccessControlExposeHeaders = strings.Join([]string{
		"Content-Length",
		"ETag",
		"Link",
		"Location",
	}, corsSep)
	AccessControlAllowCredentials = true
	AccessControlMaxAge           = strconv.Itoa(int((20 * 24 * time.Hour).Seconds())) // 20 days
)

CORS settings

View Source
var AuthorizedUserKey authKey

AuthorizedUserKey is the context value key for storing request authorization information.

View Source
var RequestIDKey requestIDKey

RequestIDKey is the context value key for storing the request ID.

View Source
var UUIDRegex = regexp.MustCompile("^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")

UUIDRegex is a UUID regex. See http://stackoverflow.com/a/13653180.

Functions

func Authenticator

func Authenticator(next http.Handler) http.Handler

Authenticator creates middleware that authenticates incoming requests using a token and checking it against the database.

func CORSHeaders

func CORSHeaders(allowedOrigins []string) func(http.Handler) http.Handler

CORSHeaders middleware inserts CORS headers into every response and sends empty responses for OPTIONS requests. This middleware does not block origins that don't match allowedOrigins.

func GetAuthorizedUser

func GetAuthorizedUser(r *http.Request) db.User

GetAuthorizedUser returns the current authorized user information.

func GetRequestID

func GetRequestID(r *http.Request) string

GetRequestID returns the request ID of a given request if it exists.

func Recoverer

func Recoverer(next http.Handler) http.Handler

Recoverer is middleware that catches panics in route handlers and recovers from them.

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID populates each request context with a unique identifier and inserts the "X-Request-ID" header into the response.

func StatusEndpoint

func StatusEndpoint(endpoint string) func(http.Handler) http.Handler

StatusEndpoint is a basic health endpoint so external services and ping this service and check if it's "available".

Types

This section is empty.

Jump to

Keyboard shortcuts

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