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 19, 2023 at 10:02 AM TheDiveO <harald.albre...@gmx.net> wrote: > 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 the > variable yourself. otherwise, wait for 1.22. or use an existing 3rd party > module. > > On Thursday, October 19, 2023 at 1:27:59 PM UTC+2 Dejan Duh wrote: > >> Hi everyone. I'm building an api with net/http and I'm having trouble >> with url variables. How can I get the url variables form the url in the >> REST way. Example, if I have a url like "http:/localhost:3000/users/:id". >> I want to get the user with the id given from the url. What is the best >> way to get the id using only the standart lib? Thanks >> > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/9b1030a6-1bc3-4b60-8e99-d98cd760beddn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/9b1030a6-1bc3-4b60-8e99-d98cd760beddn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMyFqkQN7d8XBYBvhkXY-bKLC1L8zt6OzP8UUx%2BFykgAAuAHRA%40mail.gmail.com.