encapsulate Redis base function

This commit is contained in:
landaiqing
2024-08-06 13:17:03 +08:00
parent d0496b34f0
commit 86b907d4d0
15 changed files with 493 additions and 23 deletions

26
middleware/cors.go Normal file
View File

@@ -0,0 +1,26 @@
package middleware
import (
"github.com/gin-gonic/gin"
"net/http"
)
// Cors 跨域中间件
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
origin := c.Request.Header.Get("Origin")
if origin != "" {
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization")
c.Header("Access-Control-Allow-Credentials", "true")
c.Set("content-type", "application/json")
}
//放行所有OPTIONS方法
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
c.Next()
}
}