Documentation ¶
Index ¶
- Constants
- Variables
- func Authenticator(next http.Handler) http.Handler
- func CORSHeaders(allowedOrigins []string) func(http.Handler) http.Handler
- func GetAuthorizedUser(r *http.Request) db.User
- func GetRequestID(r *http.Request) string
- func Recoverer(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func StatusEndpoint(endpoint string) func(http.Handler) http.Handler
Constants ¶
const RequestIDHeader = "X-Request-ID"
RequestIDHeader is the response header name for request IDs.
Variables ¶
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
var AuthorizedUserKey authKey
AuthorizedUserKey is the context value key for storing request authorization information.
var RequestIDKey requestIDKey
RequestIDKey is the context value key for storing the request ID.
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 ¶
Authenticator creates middleware that authenticates incoming requests using a token and checking it against the database.
func CORSHeaders ¶
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 ¶
GetAuthorizedUser returns the current authorized user information.
func GetRequestID ¶
GetRequestID returns the request ID of a given request if it exists.
func Recoverer ¶
Recoverer is middleware that catches panics in route handlers and recovers from them.
Types ¶
This section is empty.