Documentation ¶
Index ¶
- Variables
- func Bytes(b []byte) string
- func CORS(next http.Handler) http.Handler
- func CSSResponseWriter(next http.Handler) http.Handler
- func CleanPath(next http.Handler) http.Handler
- func ContentEncoding(ce string, charsets ...string) bool
- func ETag(next http.Handler) http.Handler
- func FileResponseWriter(next http.Handler) http.Handler
- func GetAuthTokenFromCookie(r *http.Request) (string, error)
- func GetAuthTokenFromHeader(r *http.Request) (string, error)
- func GetRequestId(r *http.Request) string
- func GetUrlFormat(r *http.Request) string
- func Gzip(next http.Handler) http.Handler
- func HtmlResponseWriter(next http.Handler) http.Handler
- func IsPrivateAddress(address string) (bool, error)
- func JavascriptResponseWriter(next http.Handler) http.Handler
- func JsonResponseWriter(next http.Handler) http.Handler
- func KeycloakAuthorization(next http.Handler) http.Handler
- func MsgpackResponseWriter(next http.Handler) http.Handler
- func NoCache(next http.Handler) http.Handler
- func ProtobufResponseWriter(next http.Handler) http.Handler
- func RealIP(next http.Handler) http.Handler
- func Skip() http.Handler
- func String(b string) string
- func TextResponseWriter(next http.Handler) http.Handler
- func TimeTakenLog(next http.Handler) http.Handler
- func TrueIp(r *http.Request) string
- func UrlFormat(next http.Handler) http.Handler
- func XmlResponseWriter(next http.Handler) http.Handler
- func YamlResponseWriter(next http.Handler) http.Handler
- type ContextKey
- type GzipWriter
- type MiddlewareFunc
- func AllowContentEncoding(contentEncoding ...string) MiddlewareFunc
- func AsMiddlewareFunc(handler http.Handler) MiddlewareFunc
- func Authorize(tokenMaker token.Builder, ...) MiddlewareFunc
- func BasicAuth(realm string, credentials map[string]string) MiddlewareFunc
- func CORSWithConfig(config *cors.Config) MiddlewareFunc
- func CheckUrlParams(expectedParams []string) MiddlewareFunc
- func ContentCharset(charsets ...string) MiddlewareFunc
- func ContentType(contentTypes ...string) MiddlewareFunc
- func FileServer(urlPrefix, rootPath, defaultFile string, allowDirectoryListing bool) MiddlewareFunc
- func GzipLevel(level int) MiddlewareFunc
- func Health(endpoint, message string) MiddlewareFunc
- func Maybe(mw func(http.Handler) http.Handler, maybeFn func(r *http.Request) bool) MiddlewareFunc
- func RateLimiter(limit int, burst int) MiddlewareFunc
- func Redirect(status int, path string) MiddlewareFunc
- func RequestID(requestIdHeader string) MiddlewareFunc
- func Rewrite(old, new string) MiddlewareFunc
- func SetHeader(key, value string) MiddlewareFunc
- func Static(path string, handler http.Handler) MiddlewareFunc
- type Middlewares
Constants ¶
This section is empty.
Variables ¶
var ( AuthorizationKey = "authorization" AuthorizationType = "bearer" AuthnCtxKey = &ContextKey{Name: "AuthnCtx"} )
Functions ¶
func CleanPath ¶
CleanPath middleware will clean out double slash mistakes from a user's request path. For example, if a user requests /users//1 or //users////1 will both be treated as: /users/1
func ContentEncoding ¶
func GetAuthTokenFromCookie ¶
GetAuthTokenFromCookie tries to retrieve the token from the cookie named "authorizationKey".
func GetAuthTokenFromHeader ¶
GetAuthTokenFromHeader tries to retrieve the token from the request header: "Authorization: BEARER T".
func GetRequestId ¶
func GetUrlFormat ¶
GetUrlFormat - gets the url format processed by this middleware
func IsPrivateAddress ¶
func KeycloakAuthorization ¶
KeycloakAuthorization middleware checks for Authorization header containing a Bearer token
func TimeTakenLog ¶
TimeTakenLog middleware logs time taken for each request including the RequestId This middleware needs to be used after RequestId middleware in order to obtain the RequestId value first.
func UrlFormat ¶
UrlFormat is a middleware that parses the url extension from a request path and stores it on the context. The middleware will trim the suffix from the routing path and continue routing. Routers should not include a url parameter for the suffix when using this httpmiddleware.
Example
http://domain/list/cars/1 - will store "" http://domain/list/cars/2.json - will store "json" http://domain/list/cars/3.xml - will store "xml" func routes() http.MiddlewareFunc { r := NewMux() r.Use(httpmiddleware.URLFormat) r.Handler("/cars/:id", ListCars) return r } func ListCars(w http.ResponseWriter, r *http.request) { urlFormat := httpmiddleware.GetUrlFormat(r) switch urlFormat { case "json": render.JSON(w, r, cars) case "xml:" render.XML(w, r, cars) default: render.JSON(w, r, cars) } }
Types ¶
type ContextKey ¶
type ContextKey struct {
Name string
}
func (*ContextKey) String ¶
func (k *ContextKey) String() string
type GzipWriter ¶
type GzipWriter struct { io.Writer http.ResponseWriter // contains filtered or unexported fields }
func (*GzipWriter) Flush ¶
func (w *GzipWriter) Flush() error
func (*GzipWriter) Hijack ¶
func (w *GzipWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
type MiddlewareFunc ¶
MiddlewareFunc custom type to mark httpmiddleware.
func AllowContentEncoding ¶
func AllowContentEncoding(contentEncoding ...string) MiddlewareFunc
AllowContentEncoding enforces a whitelist of request Content-Encoding otherwise responds with a 415 Unsupported Media Type status.
func AsMiddlewareFunc ¶
func AsMiddlewareFunc(handler http.Handler) MiddlewareFunc
func Authorize ¶
func Authorize(tokenMaker token.Builder, lookupTokenFunc func(r *http.Request) (string, error)) MiddlewareFunc
Authorize middleware for authorization.
func BasicAuth ¶
func BasicAuth(realm string, credentials map[string]string) MiddlewareFunc
BasicAuth implements a simple middleware handler for adding basic http auth to a route.
func CORSWithConfig ¶
func CORSWithConfig(config *cors.Config) MiddlewareFunc
CORSWithConfig creates a new cors handler with passed options.
func CheckUrlParams ¶
func CheckUrlParams(expectedParams []string) MiddlewareFunc
CheckUrlParams checks if url params come as expected to proceed processing the request
func ContentCharset ¶
func ContentCharset(charsets ...string) MiddlewareFunc
ContentCharset generates a handler that writes a 415 Unsupported Media Type response if none of the charsets match. An empty charset will allow requests with no Content-Type header or specified charset.
func ContentType ¶
func ContentType(contentTypes ...string) MiddlewareFunc
ContentType enforces a whitelist of request Content-Types otherwise responds with a 415 Unsupported Media Type status.
func FileServer ¶
func FileServer(urlPrefix, rootPath, defaultFile string, allowDirectoryListing bool) MiddlewareFunc
func GzipLevel ¶
func GzipLevel(level int) MiddlewareFunc
GzipLevel returns a middleware which compresses HTTP response using gzip compression scheme using the level specified
func Health ¶
func Health(endpoint, message string) MiddlewareFunc
Health endpoint middleware to check status on the server. Allows to pass a default message
func Maybe ¶
Maybe middleware will allow you to change the flow of the middleware stack execution depending on return value of maybeFn(request). This is useful for example if you'd like to skip a middleware handler if a request does not satisfy the maybeFn logic.
func RateLimiter ¶
func RateLimiter(limit int, burst int) MiddlewareFunc
func Redirect ¶
func Redirect(status int, path string) MiddlewareFunc
func RequestID ¶
func RequestID(requestIdHeader string) MiddlewareFunc
func Rewrite ¶
func Rewrite(old, new string) MiddlewareFunc
func SetHeader ¶
func SetHeader(key, value string) MiddlewareFunc
SetHeader is a convenience handler to set a response header key/value
type Middlewares ¶
type Middlewares []MiddlewareFunc
func (Middlewares) Append ¶
func (m Middlewares) Append(handlers ...MiddlewareFunc) (chain Middlewares)
func (Middlewares) ThenFunc ¶
func (m Middlewares) ThenFunc(fn http.HandlerFunc) http.Handler
Source Files ¶
- authorization.go
- basic-auth.go
- check-url-params.go
- clean-path.go
- content-charset.go
- content-encoding.go
- content-type.go
- cors.go
- custom-response-writer.go
- etag.go
- fs.go
- gzip.go
- health.go
- keycloak-authorization.go
- limiter.go
- maybe.go
- middlewares.go
- no-cache.go
- real-ip.go
- redirect.go
- request-id.go
- rewrite.go
- set-header.go
- skip.go
- static.go
- time-taken-log.go
- true-ip.go
- url-format.go