前言
跨域问题在前后端对接十分普遍。之所以立为解决方案,是因为历史原本的解决跨域的问题,没有效果。
实现
import "github.com/gin-contrib/cors"
// r.Use(AllowAll())
func AllowAll() gin.HandlerFunc{
cfg := cors.Config{
AllowMethods: []string{
"*"},
AllowHeaders: []string{
"*"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}
cfg.AllowAllOrigins = true
ret