package main
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"
)
func main() {
router := gin.Default()
// CORS for https://foo.com and https://github.com origins, allowing:
// - PUT and PATCH methods
// - Origin header
// - Credentials share
// - Preflight requests cached for 12 hours
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"https://foo.com"},
AllowMethods: []string{"PUT", "PATCH"},
AllowHeaders: []string{"Origin", "token"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "https://github.com"
},
MaxAge: 12 * time.Hour,
}))
router.GET("/", func(context *gin.Context) {
context.String(http.StatusOK, "hello world")
})
router.Run()
}
here is the code:
browser response:

postman response

can not find
Access-Control-Allow-OriginAccess-Control-Expose-Headersand so on