...
1 package main
2
3 import (
4 "time"
5
6 "github.com/gin-contrib/cors"
7 "github.com/gin-gonic/gin"
8 )
9
10 func main() {
11 router := gin.Default()
12
13
14
15
16
17 router.Use(cors.New(cors.Config{
18 AllowOrigins: []string{"https://foo.com"},
19 AllowMethods: []string{"PUT", "PATCH"},
20 AllowHeaders: []string{"Origin"},
21 ExposeHeaders: []string{"Content-Length"},
22 AllowCredentials: true,
23 AllowOriginFunc: func(origin string) bool {
24 return origin == "https://github.com"
25 },
26 MaxAge: 12 * time.Hour,
27 }))
28
29 if err := router.Run(); err != nil {
30 panic(err)
31 }
32 }
33
View as plain text