如何在 Google App Engine 中使用 Gin-gonic 中间件?
How to use Gin-gonic middleware with Google App Engine?
我在 Google App Engine 平台上为我的网站使用 Gin-Gonic。
一切正常,但我开始需要使用一些中间件。
当我尝试使用时:
router.Use(MyMiddleware())
MyMiddleware()
返回的中间件好像不是运行.
所以我的问题是:
- 在使用 GAE 时是否可以使用 gin-gonic 中间件?
- 如果可以,我该如何实现?
谢谢!
这是我的消息来源:
main.go :
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 中间件 和 Auth 中间件
的项目中查看此文件
https://github.com/wilsontamarozzi/panda-api/blob/master/routers/router.go
我在 Google App Engine 平台上为我的网站使用 Gin-Gonic。 一切正常,但我开始需要使用一些中间件。
当我尝试使用时:
router.Use(MyMiddleware())
MyMiddleware()
返回的中间件好像不是运行.
所以我的问题是:
- 在使用 GAE 时是否可以使用 gin-gonic 中间件?
- 如果可以,我该如何实现?
谢谢!
这是我的消息来源:
main.go :
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 中间件 和 Auth 中间件
的项目中查看此文件https://github.com/wilsontamarozzi/panda-api/blob/master/routers/router.go