結果順序
initMiddlewareOne-init
initMiddlewareTwo-init
路由的程式
initMiddlewareTwo
initMiddlewareOne
程式碼
package main
import (
"QMApi/routers"
"github.com/gin-gonic/gin"
"fmt")
func initMiddlewareOne(c *gin.Context) {
fmt.Println("initMiddlewareOne-init")
c.Next()
fmt.Println("initMiddlewareOne")
}
func initMiddlewareTwo(c *gin.Context) {
fmt.Println("initMiddlewareTwo-init")
c.Next()
fmt.Println("initMiddlewareTwo")
}
func main() {
r := gin.Default()
r.GET("king", initMiddlewareOne, initMiddlewareTwo, func(c *gin.Context) {
c.String(200, "ok")
})
routers.AdminRoutersInit(r)
routers.ApiRoutersInit(r)
r.Run(":9090")
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結