github.com/songzhibin97/gkit@v1.2.13/tools/bind/xml.go (about) 1 package bind 2 3 import ( 4 "bytes" 5 "encoding/xml" 6 "io" 7 "net/http" 8 ) 9 10 type xmlBinding struct{} 11 12 func (xmlBinding) Name() string { 13 return "xml" 14 } 15 16 func (xmlBinding) Bind(req *http.Request, obj interface{}) error { 17 return decodeXML(req.Body, obj) 18 } 19 20 func (xmlBinding) BindBody(body []byte, obj interface{}) error { 21 return decodeXML(bytes.NewReader(body), obj) 22 } 23 24 func decodeXML(r io.Reader, obj interface{}) error { 25 decoder := xml.NewDecoder(r) 26 return decoder.Decode(obj) 27 }