我的 Golang API 中有一个user.save路由(如下),可用于create和update用户,具体取决于id请求对象中是否提供了 an 。该路由使用auth其他路由也使用的中间件。
api.POST("/user.save", auth(), user.Save())
api.POST("/user.somethingElse", auth(), user.SomethingElse())
这是我的中间件:
func auth() gin.HandlerFunc {
return func(c *gin.Context) {
//I would like to know here if user.save was the route called
//do authy stuff
}
}
我在想,如果我可以在auth中间件中检测到user.save路由是否被调用,那么我可以检查是否id包含 an 并决定是继续还是返回。