Skip to content

[REQ] [go-gin-server] Add featureCORS option to enable CORS middleware #11186

@kumo-rn5s

Description

@kumo-rn5s

Is your feature request related to a problem? Please describe.

Go-Gin-Server supporting file routers.go start a router without any cors configurations.

router := gin.Default()
for _, route := range routes {
  switch route.Method {
  case http.MethodGet:
	  router.GET(route.Pattern, route.HandlerFunc)
  case http.MethodPost:
	  router.POST(route.Pattern, route.HandlerFunc)
  case http.MethodPut:
	  router.PUT(route.Pattern, route.HandlerFunc)
  case http.MethodPatch:
	  router.PATCH(route.Pattern, route.HandlerFunc)
  case http.MethodDelete:
	  router.DELETE(route.Pattern, route.HandlerFunc)
  }
}

Describe the solution you'd like

Like Go-Server featureCORS option, cors configurations are added to router before route paths are holding, similar processing is required by Go-Gin-Server.

https://github.com/gin-contrib/cors

 router := gin.Default()
  router.Use(cors.New(cors.Config{
    AllowOrigins:     []string{"https://foo.com"},
    AllowMethods:     []string{"PUT", "PATCH"},
    AllowHeaders:     []string{"Origin"},
    ExposeHeaders:    []string{"Content-Length"},
    AllowCredentials: true,
    AllowOriginFunc: func(origin string) bool {
      return origin == "https://github.com"
    },
    MaxAge: 12 * time.Hour,
  }))
  router.Run()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions