With()
Negroni 还有一个便利的函数叫 With
. With
函数可以把一个或多个 Handler
实例和接收者处理器集合组合成新的处理器集合,并返回新的 Negroni
实例对象。
- // middleware we want to reuse
- common := negroni.New()
- common.Use(MyMiddleware1)
- common.Use(MyMiddleware2)
- // `specific` is a new negroni with the handlers from `common` combined with the
- // the handlers passed in
- specific := common.With(
- SpecificMiddleware1,
- SpecificMiddleware2
- )