Most flexible muxer/router in golang

Hi,
Currently almost 99% of my projects are api related /rest|rpc oriented/, eg no templates. I am considering golang as very good /if not the best/ platform to use for my needs.

At the moment I’m experimenting with different routers/muxer. Tried gorilla/mux, httprouter, core net/http and several frameworks - beego, gin, buffalo, chi … Some of them are already using some of the above muxers internally/gin is using httprouter, buffalo -> gorilla/mux …

Also, I dont quite need full web framework.

The problem I am facing is that some of them have limitations - here are some examples:

In gin we cant have:

...
r.GET("/api/v1/order/:orderId/order_lines/:orderLineId", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "some message here",
		})
	})

	r.GET("/api/v1/order/:orderId/order_lines/stats", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"stats": "some other message here",
		})
	})
...

we just cant.

About that, I’ve found smth similar here -> https://github.com/julienschmidt/httprouter/issues/73, https://github.com/julienschmidt/httprouter/issues/73#issuecomment-110228393 but still its not solved/implemented.

In gorilla/mux, if you want smth similar, like :

		app.GET("/order/{id}", OrderFetchHandler)
		app.GET("/order/stat", OrderStatHandler)

will not quite work.
It should be :

...
		app.GET("/order/stat", OrderStatHandler)
		app.GET("/order/{id}", OrderFetchHandler)
...

Eg, the static one should be BEFORE the one with param.

Imagine a project, with dozens/hundreds of enpoints …

Currently I am thinking about chi:

	r.Get("/api/v1/some_resource/{id}", func(w http.ResponseWriter, r *http.Request) {
		id := chi.URLParam(r, "id")
		w.Write([]byte("Id: " + id))
	})

	r.Get("/api/v1/some_resource/stats", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("/api/v1/some_resource/stats"))
	})

It doesnt matter the order, eg which one is defined first, its just working.

Any suggestions will be appreciated.

Note: I dont need “the fastest” or “the coolest” one. What I need, especially when dealing with apis kind of work is the least limited one/especially with no url pattern/maching limitations/, eg the most flexible one.

1 Like

chi mux supports regexes so you should be able to do this.

Ok, as I mentioned, I am testing chi atm.
But, is there any other muxer, which hasnt these limitations?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.