Discussion on: Building a Web App With Go, Gin and React

agrim profile image
Agrim Prasad

Many thanks for this great blog post!

We've been using Gin as our web framework in production, and while it holds up very well under high load, we've seen some issues with the router used within the framework. The issue is detailed in github.com/gin-gonic/gin/issues/388

In brief, if you have two routes defined as follows, you'll see a runtime panic :

r.GET("/teachers/list", func (c *gin.Context){})
r.GET("/teachers/:id/profile", func (c *gin.Context){})

This is because gin's built-in router (based on httprouter) can't handle such wildcard based routing properly. As a result, RESTful services are difficult to define around resource names.

I've been exploring alternatives to using gin, and it seems like go-chi is the most simple and idiomatic router around. It could successfully handle such wildcard based routing. Furthermore, it uses the native Go context object (rather than Gin's custom context object), and its middlewares and handlers are portable across other routing libraries such as gorilla/mux (in case you want to change in the future).

Some comparisons between simple Go http routers made by me in this repo