This repository provides a way to share your Iris' specific middleware with the rest of us. You can view real implementations by pressing here.
The only requirement is the Go Programming Language, at least 1.8
$ go get github.com/iris-contrib/middleware/...
Explore these questions or navigate to the community chat.
The Community.
This project is licensed under the MIT License.
License can be found here.
Middleware are just handlers which can be served before or after the main handler, can transfer data between handlers and communicate with third-party libraries, they are just functions.
$ go get -u github.com/iris-contrib/middleware/$FOLDERNAME
NOTE: When you install one middleware you will have all of them downloaded & installed, no need to re-run the go get foreach middeware.
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 *iris.Context){},myMiddleware3)
{
//....
}
To all routes
app.UseFunc(func(ctx *iris.Context){}, myMiddleware2)
To global, all routes on all subdomains on all parties
app.UseGlobalFunc(func(ctx *iris.Context){}, myMiddleware2)
Yes you can, just pass the Handler inside the iris.ToHandler
in order to be converted into iris.HandlerFunc and register it as you saw before.
package main
import (
"gopkg.in/kataras/iris.v6"
)
func main() {
app := iris.New()
sillyHTTPHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
println(r.RequestURI)
})
sillyConvertedToIris := iris.ToHandler(sillyHTTPHandler)
// ToHandler can take (http.ResponseWriter, *http.Request, next http.Handler) too!
app.Use(sillyConvertedToIris)
app.Listen(":8080")
}