zhangqian
2024-03-22 9c03486e5a7f0b0298436c4b6227f21cd3c10649
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package middleware
 
import (
    "net/http"
 
    "github.com/gin-gonic/gin"
)
 
// Authorized blocks unauthorized requestrs
func Authorized(c *gin.Context) {
    _, exists := c.Get("parentId")
    if !exists {
        c.JSON(http.StatusUnauthorized, gin.H{"status": http.StatusUnauthorized, "message": "must login"})
        c.Abort()
    }
}