first commit
This commit is contained in:
30
pkg/middleware/authorize.go
Normal file
30
pkg/middleware/authorize.go
Normal file
@ -0,0 +1,30 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/anxpp/common-utils/logg"
|
||||
"github.com/anxpp/common-utils/net"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func Authorize() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
inputToken := c.Request.Header.Get("X-Token")
|
||||
if len(inputToken) == 0 {
|
||||
c.JSON(http.StatusOK, net.Custom(500, "缺少授权token"))
|
||||
c.Abort()
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func LogRequest() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
decodedStr, _ := url.QueryUnescape(c.Request.RequestURI)
|
||||
logg.Info("request:", c.Request.RemoteAddr, decodedStr)
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user