package middleware import ( "Ic_ouath/app/e" "Ic_ouath/utils" "github.com/gin-gonic/gin" ) func Authentication() gin.HandlerFunc { return func(c *gin.Context) { header := c.GetHeader("Authorization") token, err := utils.ParseToken(header) if err != e.SUCCESS { e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg()) c.Abort() return } else if token.Role != "admin" { e.ResponseWithMsg(c, e.TokenIsInvalid, e.TokenIsInvalid.GetMsg()) c.Abort() } c.Set("user_id", token.UserId) c.Next() } }