middleware

module
v0.0.0-...-810cc64 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2017 License: MIT

README

Build Status License CHANGELOG/HISTORY

This repository provides a way to share your Iris' specific middleware with the rest of us. You can view real implementations by pressing here.

Installation

The only requirement is the Go Programming Language, at least 1.8

$ go get github.com/iris-contrib/middleware/...

FAQ

Explore these questions or navigate to the community chat.

People

The Community.

License

This project is licensed under the MIT License.

License can be found here.

What?

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.

How can I install a middleware?

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

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 *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)

Can I use standard net/http handler with Iris?

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.

handler which has the form of http.Handler/HandlerFunc

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

Directories

Path Synopsis
jwt
_example
Iris provides some basic middleware, most for your learning courve.
Iris provides some basic middleware, most for your learning courve.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL