Categorygithub.com/hidevopsio/middleware
module
0.0.0-20240811142457-7e33354fa83f
Repository: https://github.com/hidevopsio/middleware.git
Documentation: pkg.go.dev

# README

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.

Build status

Installation

$ 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.

MiddlewareDescriptionExample
jwtMiddleware checks for a JWT on the Authorization header on incoming requests and decodes it.jwt/_example
corsHTTP Access Control.cors/_example
secureMiddleware that implements a few quick security wins.secure/_example
tollboothGeneric middleware to rate-limit HTTP requests.tollbooth/_examples/limit-handler
cloudwatchAWS cloudwatch metrics middleware.cloudwatch/_example
new relicOfficial New Relic Go Agent.newrelic/_example
prometheusEasily create metrics endpoint for the prometheus instrumentation toolprometheus/_example
casbinAn authorization library that supports access control models like ACL, RBAC, ABACcasbin/_examples
ravenSentry client in Goraven/_example
csrfCross-Site Request Forgery Protectioncsrf/_example

How can I register middleware?

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)

Can I use standard net/http handler with iris?

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.

Convert handler which has the form of http.Handler/HandlerFunc

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"))
}

Contributing

If you are interested in contributing to this project, please push a PR.

People

List of all contributors

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Package tollboothic v2(latest) provides rate-limiting logic to iris request handlers.