json.go 518 B

12345678910111213141516171819202122232425
  1. package binder
  2. import (
  3. "github.com/gofiber/utils/v2"
  4. )
  5. // JSONBinding is the JSON binder for JSON request body.
  6. type JSONBinding struct {
  7. JSONDecoder utils.JSONUnmarshal
  8. }
  9. // Name returns the binding name.
  10. func (*JSONBinding) Name() string {
  11. return "json"
  12. }
  13. // Bind parses the request body as JSON and returns the result.
  14. func (b *JSONBinding) Bind(body []byte, out any) error {
  15. return b.JSONDecoder(body, out)
  16. }
  17. // Reset resets the JSONBinding binder.
  18. func (b *JSONBinding) Reset() {
  19. b.JSONDecoder = nil
  20. }