gin-contrib / cors

Official CORS gin's middleware
https://gin-gonic.github.io/gin/
MIT License
1.77k stars 181 forks source link

Unable to run example with latest Gin #54

Closed mattsrobot closed 5 years ago

mattsrobot commented 5 years ago

When I import the following.

import (
    "github.com/gin-contrib/cors"
    "github.com/gin-gonic/gin"
)

Then I try use the example:

    router := gin.New()

    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,
    }))

I get the following error:

cannot use cors.New(cors.Config literal) (type "github.com/gin-gonic/gin".HandlerFunc) as type "mend/vendor/github.com/gin-gonic/gin".HandlerFunc in argument to router.Use
mattsrobot commented 5 years ago

Issue was resolved with dep ensure and restarting Visual Code. Not sure what the problem was entirely...