Skip to content

Convert func(next http.Handler) http.Handler middleware #1885

Answered by kataras
gf3 asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @gf3,

It's easy to conver such middlewares to Iris but if you don't want and you just want to wrap it, then use the WrapRouter, example:

app := iris.New()
// ...

loggerMiddleware := AuthMiddleware(logger)
app.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {
	loggerMiddleware(router).ServeHTTP(w, r)
})

Full code example:

package main

import (
	"context"
	"net/http"

	"github.com/kataras/iris/v12"
)

func main() {
	app := iris.New()

	httpThirdPartyWrapper := StandardWrapper(Options{
		Message: "test_value",
	})
	app.WrapRouter(func(w http.ResponseWriter, r *http.Request, router http.HandlerFunc) {
		httpThirdPartyWrapper(router).ServeHTTP(w, r)
	})

	

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by kataras
Comment options

You must be logged in to vote
1 reply
@kataras
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants