package mw import ( "applet/app/admin/md" "applet/app/admin/svc" "applet/app/e" "applet/app/utils" "fmt" "github.com/gin-gonic/gin" ) // CheckPermission 检查权限 func CheckPermission(c *gin.Context) { admin := svc.GetUser(c) rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, utils.GetIP(c.Request), utils.AnyToString(admin.AdmId)) isHasPermission, err := svc.CheckUserRole(rolePermissionKey, c.Request.RequestURI, admin.AdmId) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } if !isHasPermission { e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员") return } c.Next() }