我在Google App Engine平台上为我的网站使用Gin-Gonic。一切正常,但我开始使用一些中间件。
当我尝试使用:
router.Use(MyMiddleware())
MyMiddleware()
返回的中间件似乎没有运行。
所以我的问题是:
- 使用
- GAE 时是否可以使用杜松子酒中间件?
- 如果是这样,我该如何实现它?
谢谢!
这是我的消息来源:
主去 :
func init() {
router := routes.Router()
// Set the config to the context
router.Use(SetConfiguration())
http.Handle("/", router)
}
func SetConfiguration() gin.HandlerFunc {
configuration := config.GetConfiguration()
return func(c *gin.Context) {
c.Set("config", configuration)
c.Next()
}
}
PS :routes.Router()
只需设置一个带有gin.New()
的路由器并添加一些路由即可。
中间件路由应该是第一个添加到其他路由之前。从我的一个项目中查看此文件,其中我使用 CORS 中间件和身份验证中间件
https://github.com/wilsontamarozzi/panda-api/blob/master/routers/router.go