query.go 829 B

1234567891011121314151617181920212223242526272829303132333435
  1. package binder
  2. import (
  3. "github.com/gofiber/utils/v2"
  4. "github.com/valyala/fasthttp"
  5. )
  6. // QueryBinding is the query binder for query request body.
  7. type QueryBinding struct {
  8. EnableSplitting bool
  9. }
  10. // Name returns the binding name.
  11. func (*QueryBinding) Name() string {
  12. return "query"
  13. }
  14. // Bind parses the request query and returns the result.
  15. func (b *QueryBinding) Bind(reqCtx *fasthttp.Request, out any) error {
  16. data := make(map[string][]string)
  17. for key, val := range reqCtx.URI().QueryArgs().All() {
  18. k := utils.UnsafeString(key)
  19. v := utils.UnsafeString(val)
  20. if err := formatBindData(b.Name(), out, data, k, v, b.EnableSplitting, true); err != nil {
  21. return err
  22. }
  23. }
  24. return parse(b.Name(), out, data)
  25. }
  26. // Reset resets the QueryBinding binder.
  27. func (b *QueryBinding) Reset() {
  28. b.EnableSplitting = false
  29. }