Skip to content
Myr

xml.go

This file

Path

binding/xml.go

34 lines · 677 bytes · Go

Last changed by

ci(golangci-lint): update configuration and fix lint issues (#4247)Flc゛before adoptionc4287b1

History of this file

Take it

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package binding67import (8	"bytes"9	"encoding/xml"10	"io"11	"net/http"12)1314type xmlBinding struct{}1516func (xmlBinding) Name() string {17	return "xml"18}1920func (xmlBinding) Bind(req *http.Request, obj any) error {21	return decodeXML(req.Body, obj)22}2324func (xmlBinding) BindBody(body []byte, obj any) error {25	return decodeXML(bytes.NewReader(body), obj)26}2728func decodeXML(r io.Reader, obj any) error {29	decoder := xml.NewDecoder(r)30	if err := decoder.Decode(obj); err != nil {31		return err32	}33	return validate(obj)34}