Just found an interesting issue:

    r.Static("/assets/", p.rootFolder+"/assets")
    r.GET("/:code", p.redirectHandler)

Generates:

panic: wildcard route ':code' conflicts with existing children in path '/:code'

Seems like it's due to the fact that Static uses *filename wildcard. My plane is due in soon, so can't dig into it now, but I think any static wildcards should be generated below the url path specified, not within root domain.

As in:
/assets/*filename
instead of 
/*filename

Any thoughts?

Comment From: manucorporat

@nazwa the problem is not r.Static("/assets/", p.rootFolder+"/assets"), in fact, it registers /assets/*filename.

The conflict happens because: /assets would match /assets/*filename and /:code.

HttpRouter developer is working in a non-strict mode that will allow this to work.

Workaround:

    r.GET("/c/:code", p.redirectHandler)

Comment From: nazwa

I thought placeholders only matched up to the first slash in the path? Are you saying that r.GET("/:code", p.redirectHandler) will match /123 and /123/hello? Thought that's what the wildcard option was for.

Comment From: StarpTech

I also faced the same issue. The root of the issue is the used router https://github.com/julienschmidt That issue is well known and not fixed since a year

https://github.com/julienschmidt/httprouter/issues/210 https://github.com/julienschmidt/httprouter/issues/175 https://github.com/julienschmidt/httprouter/issues/183 ...

I don't know why gin use this buggy router implementation there are some great alternatives https://github.com/avelino/awesome-go#routers

Comment From: xaionaro

Confirm. My problem:

[GIN-debug] POST   /auth.json                --> github.com/appleboy/gin-jwt.(*GinJWTMiddleware).LoginHandler-fm (3 handlers)
[GIN-debug] POST   /refresh_token.json       --> github.com/appleboy/gin-jwt.(*GinJWTMiddleware).RefreshHandler-fm (3 handlers)
[GIN-debug] POST   /sign_up.json             --> github.com/appleboy/gin-jwt.(*GinJWTMiddleware).LoginHandler-fm (4 handlers)
[GIN-debug] GET    /ping.json                --> github.com/dxcenter/chess/serverMethods.Ping (3 handlers)
[GIN-debug] GET    /whoami.json              --> github.com/dxcenter/chess/serverMethods.Whoami (5 handlers)
[GIN-debug] GET    /games.json               --> github.com/dxcenter/chess/serverMethods.Games (5 handlers)
[GIN-debug] GET    /games/:game_id/status.json --> github.com/dxcenter/chess/serverMethods.GameStatus (5 handlers)
[GIN-debug] POST   /games.json               --> github.com/dxcenter/chess/serverMethods.NewGame (5 handlers)
[GIN-debug] POST   /games/:game_id/move.json --> github.com/dxcenter/chess/serverMethods.Move (5 handlers)
[GIN-debug] GET    /frontend/*filepath       --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD   /frontend/*filepath       --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] GET    /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD   /static/*filepath         --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] GET    /css/*filepath            --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD   /css/*filepath            --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] GET    /                         --> github.com/gin-gonic/gin.(*RouterGroup).StaticFile.func1 (3 handlers)
[GIN-debug] HEAD   /                         --> github.com/gin-gonic/gin.(*RouterGroup).StaticFile.func1 (3 handlers)
[GIN-debug] GET    /games/new                --> github.com/gin-gonic/gin.(*RouterGroup).StaticFile.func1 (3 handlers)
panic: path segment 'new' conflicts with existing wildcard ':game_id' in path '/games/new'

I don't see any possibility how /games/new can be in a conflict with /games/:game_id/status.json.

The line:

r.StaticFile("/games/new", "frontend/build/index.html")

Comment From: lincolnzhou

Is there another solution?

Comment From: odiferousmint

I have an issue with this as well.

router.Static("/", "./static")
router.GET("/socket.io/", gin.WrapH(server))
router.POST("/socket.io/", gin.WrapH(server))

This works with many other routers but not with Gin! :( I want to serve the directory ./static which contains index.html and js/socket.io.js. How am I supposed to do this?! It makes no sense for it to be in conflict:

/index.html
/js/socket.io.js
/socket.io/

Is there going to be a better way of handling conflicts or is it possible to use a different router? How am I supposed to go about this?

I get this error, by the way:

[GIN-debug] GET    /*filepath                --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] HEAD   /*filepath                --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
[GIN-debug] GET    /socket.io/               --> github.com/gin-gonic/gin.WrapH.func1 (3 handlers)
panic: '/socket.io/' in new path '/socket.io/' conflicts with existing wildcard '/*filepath' in existing prefix '/*filepath'

There are two workarounds that seem to work:

    router.StaticFile("/", "static/index.html")
    router.StaticFile("/js/socket.io.js", "static/js/socket.io.js")

    router.GET("/socket.io/", gin.WrapH(server))
    router.POST("/socket.io/", gin.WrapH(server))

and:

    router.GET("/", func(c *gin.Context) {
        c.Redirect(http.StatusMovedPermanently, "public/")
    })

    router.GET("/socket.io/", gin.WrapH(server))
    router.POST("/socket.io/", gin.WrapH(server))
    router.StaticFS("/public", http.Dir("./static"))

Comment From: jseparator

router.NoRoute(gin.WrapH(http.FileServer(http.Dir("static"))))
router.GET("/socket.io/", gin.WrapH(server))
router.POST("/socket.io/", gin.WrapH(server))