This repository provides a way to share any minor handlers for iris web framework. You can view the built'n supported handlers by pressing here.
$ go get github.com/hidevopsio/middleware/...
Middleware is just a chain handlers which can be executed before or after the main handler, can transfer data between handlers and communicate with third-party libraries, they are just functions.
Middleware | Description | Example |
---|---|---|
jwt | Middleware checks for a JWT on the Authorization header on incoming requests and decodes it. |
jwt/_example |
cors | HTTP Access Control. | cors/_example |
secure | Middleware that implements a few quick security wins. | secure/_example |
tollbooth | Generic middleware to rate-limit HTTP requests. | tollbooth/_examples/limit-handler |
cloudwatch | AWS cloudwatch metrics middleware. | cloudwatch/_example |
new relic | Official New Relic Go Agent. | newrelic/_example |
prometheus | Easily create metrics endpoint for the prometheus instrumentation tool | prometheus/_example |
casbin | An authorization library that supports access control models like ACL, RBAC, ABAC | casbin/_examples |
raven | Sentry client in Go | raven/_example |
csrf | Cross-Site Request Forgery Protection | csrf/_example |
To a single route
app := iris.New()
app.Get("/mypath", myMiddleware1, myMiddleware2, func(ctx iris.Context){}, func(ctx iris.Context){}, myMiddleware5,myMainHandlerLast)
To a party of routes or subdomain
myparty := app.Party("/myparty", myMiddleware1,func(ctx context.Context){},myMiddleware3)
{
//....
}
To all routes
app.Use(func(ctx iris.Context){}, myMiddleware2)
To global, all routes, parties and subdomains
app.UseGlobal(func(ctx iris.Context){}, myMiddleware2)
Yes you can, just pass the Handler inside the iris.FromStd
in order to be converted into iris.Handler and register it as you saw before.
package main
import (
"github.com/hidevopsio/iris"
)
func main() {
app := iris.New()
sillyHTTPHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
println(r.RequestURI)
})
sillyConvertedToIon := iris.FromStd(sillyHTTPHandler)
// FromStd can take (http.ResponseWriter, *http.Request, next http.Handler) too!
app.Use(sillyConvertedToIon)
app.Run(iris.Addr(":8080"))
}
If you are interested in contributing to this project, please push a PR.