How do I pass multiple get parameters to a url in Echo? #2234
Answered
by
aldas
lolo02afon
asked this question in
Q&A
-
In the From here I was asked how to pass more than one parameter (how to continue writing a static url after the parameter is also interesting, but the main thing for me is to get an answer to the first question)? |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Aug 4, 2022
Replies: 1 comment 2 replies
-
Just add another Example: func main() {
e := echo.New()
e.GET("/groups/:gid/users/:uid", func(c echo.Context) error {
groupID := c.Param("gid")
userID := c.Param("uid")
lang := c.QueryParam("lang")
return c.String(http.StatusOK, fmt.Sprintf("group id from path: %v, user id from path: %v, lang from query: %v", groupID, userID, lang))
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
log.Print(fmt.Errorf("error when starting HTTP server: %w", err))
}
} Test with curl: x@x:~$ curl -v http://localhost:8080/groups/1/users/999?lang=en
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /groups/1/users/999?lang=en HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: text/plain; charset=UTF-8
< Date: Thu, 04 Aug 2022 10:41:59 GMT
< Content-Length: 66
<
* Connection #0 to host localhost left intact
group id from path: 1, user id from path: 999, lang from query: en |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
lolo02afon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add another
:xx
in path when you add new routeExample:
Test with curl: