xml.go 601 B

12345678910111213141516171819202122232425262728293031
  1. package binder
  2. import (
  3. "fmt"
  4. "github.com/gofiber/utils/v2"
  5. )
  6. // XMLBinding is the XML binder for XML request body.
  7. type XMLBinding struct {
  8. XMLDecoder utils.XMLUnmarshal
  9. }
  10. // Name returns the binding name.
  11. func (*XMLBinding) Name() string {
  12. return "xml"
  13. }
  14. // Bind parses the request body as XML and returns the result.
  15. func (b *XMLBinding) Bind(body []byte, out any) error {
  16. if err := b.XMLDecoder(body, out); err != nil {
  17. return fmt.Errorf("failed to unmarshal xml: %w", err)
  18. }
  19. return nil
  20. }
  21. // Reset resets the XMLBinding binder.
  22. func (b *XMLBinding) Reset() {
  23. b.XMLDecoder = nil
  24. }