Skip to content

How do I pass multiple get parameters to a url in Echo? #2234

Answered by aldas
lolo02afon asked this question in Q&A
Discussion options

You must be logged in to vote

Just add another :xx in path when you add new route

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/u…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lolo02afon
Comment options

@aldas
Comment options

aldas Aug 4, 2022
Maintainer

Answer selected by lolo02afon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants