rbac/middleware/rbac.go
zhangkun9038@dingtalk.com 375b305ab4 aliyun-deepseek-r1
2025-02-20 11:29:57 +08:00

33 lines
699 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package middlewares
import (
"github.com/gin-gonic/gin"
"net/http"
)
func RBACMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
// 获取用户ID
userID, exists := c.Get("userID")
if !exists {
utils.Error(c, http.StatusForbidden, "User authentication required")
c.Abort()
return
}
// 获取请求方法和路径
method := c.Request.Method
path := c.FullPath()
// 这里需要实现RBAC检查逻辑示例代码
// 实际应该查询用户的角色权限是否匹配当前请求
// if !checkPermission(userID, method, path) {
// utils.Error(c, http.StatusForbidden, "Access denied")
// c.Abort()
// return
// }
c.Next()
}
}