feat: add SproutWorkCollect apps
This commit is contained in:
27
SproutWorkCollect-Backend-Golang/internal/middleware/auth.go
Normal file
27
SproutWorkCollect-Backend-Golang/internal/middleware/auth.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AdminAuth returns a Gin middleware that validates the admin token.
|
||||
// The token may be supplied via the `token` query parameter or the
|
||||
// `Authorization` request header.
|
||||
func AdminAuth(token string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
t := c.Query("token")
|
||||
if t == "" {
|
||||
t = c.GetHeader("Authorization")
|
||||
}
|
||||
if t != token {
|
||||
c.AbortWithStatusJSON(http.StatusForbidden, gin.H{
|
||||
"success": false,
|
||||
"message": "权限不足",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user