Gin does this directly. There is nothing complicated it does. Something
like:
group := engine.Group("/service/v1")
group.GET("user/:id", handler)
And then in the handler:
id := c.Param("id")
And the rest is what ever is yours. "engine" is a gin engine and 'c' is a
gin context.
On Thu, Oct
stdlib only with upcoming 1.22 which isn't yet released, see
https://eli.thegreenplace.net/2023/better-http-server-routing-in-go-122/
gorilla mux is another 3rd party muxer with variable support
https://github.com/gorilla/mux
the "best" way using only stdlib mux is to parse the path and extract
I'm not sure what the best way is.
But I think you can refer to the existing solutions. For example gin, mux.
Link: https://github.com/gin-gonic/gin/blob/master/tree.go#L116
在2023年10月19日星期四 UTC+8 19:27:59 写道:
> Hi everyone. I'm building an api with net/http and I'm having trouble
> with url