QueryParser

This method is similar to BodyParser, but for query parameters.

  1. func (c *Ctx) QueryParser(out interface{}) error
  1. // Field names should start with an uppercase letter
  2. type Person struct {
  3. Name string `query:"name"`
  4. Pass string `query:"pass"`
  5. Products []string `query:"products"`
  6. }
  7. app.Get("/", func(c *fiber.Ctx) error {
  8. p := new(Person)
  9. if err := c.QueryParser(p); err != nil {
  10. return err
  11. }
  12. log.Println(p.Name) // john
  13. log.Println(p.Pass) // doe
  14. log.Println(p.Products) // [shoe, hat]
  15. // ...
  16. })
  17. // Run tests with the following curl command
  18. // curl -X POST "http://localhost:3000/?name=john&pass=doe&products=shoe,hat"