Coder Social home page Coder Social logo

Comments (6)

RCM7 avatar RCM7 commented on July 19, 2024 4

did you import cors "github.com/rs/cors/wrapper/gin" ?
Also, would really help if you put the snippet with markdown code...

from cors.

gondar00 avatar gondar00 commented on July 19, 2024 1

The error is -

cannot use "github.com/rs/cors/wrapper/gin".AllowAll() (type "github.com/gin-gonic/gin".HandlerFunc) as type "github.com/<your workspace>/vendor/github.com/gin-gonic/gin".HandlerFunc in argument to router.Use

This is due to your dependencies not being updated

go get -u github.com/rs/cors/wrapper/gin
godep save

and this should fix the above issue

from cors.

emmanuelbenson avatar emmanuelbenson commented on July 19, 2024

did you import cors "github.com/rs/cors/wrapper/gin" ?
Also, would really help if you put the snippet with markdown code...

Yes I did.

r := gin.Default()
r.Use(cors.Default())
v1 := r.Group("/v1")
{
item := v1.Group("/item")
{
item.POST("/new", controllers.AddItem)
item.GET("/", controllers.GetAllItems)
item.GET("/:id", controllers.GetItem)
item.PUT("/update", controllers.UpdateItem)
item.DELETE("/", controllers.DeleteItem)
}
verify := v1.Group("/verify")
{
verify.POST("/", controllers.VerifyItem)
}
}
return r

from cors.

rs avatar rs commented on July 19, 2024

Please include the imports you are using in your snippet.

from cors.

bcho avatar bcho commented on July 19, 2024

@emmanuelbenson did you try putting:

r.Use(cors.Default())

to the last (before return):

r.Use(cors.Default())
return r

This is likely due to no OPTIONS routes defined for the router, gin will just return 404. But if we put the cors into the bottom (i.e. the last one in the router middleware stack), it will catch all unhandled request (and generate a cors response).

from cors.

jub0bs avatar jub0bs commented on July 19, 2024

@rs This issue could likely be closed.

from cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.