This repository provides a way to share any minor handlers for ion web framework. You can view the built'n supported handlers by pressing here.
$ go get github.com/get-ion/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 |
To a single route
app := ion.New()
app.Get("/mypath", myMiddleware1, myMiddleware2, func(ctx context.Context){}, func(ctx context.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 context.Context){}, myMiddleware2)
To global, all routes on all subdomains on all parties
app.UseGlobal(func(ctx context.Context){}, myMiddleware2)
Yes you can, just pass the Handler inside the ion.FromStd
in order to be converted into context.Handler and register it as you saw before.
package main
import (
"github.com/get-ion/ion"
"github.com/get-ion/ion/context"
)
func main() {
app := ion.New()
sillyHTTPHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
println(r.RequestURI)
})
sillyConvertedToIon := ion.FromStd(sillyHTTPHandler)
// FromStd can take (http.ResponseWriter, *http.Request, next http.Handler) too!
app.Use(sillyConvertedToIon)
app.Run(ion.Addr(":8080"))
}
If you are interested in contributing to this project, please push a PR.