github.com/abemedia/go-don@v0.2.2-0.20240329015135-be88e32bb73b/encoding/xml/xml.go (about) 1 // Package xml provides encoding and decoding of XML data. 2 package xml 3 4 import ( 5 "encoding/xml" 6 7 "github.com/abemedia/go-don/encoding" 8 "github.com/valyala/fasthttp" 9 ) 10 11 func decodeXML(ctx *fasthttp.RequestCtx, v any) error { 12 return xml.NewDecoder(ctx.RequestBodyStream()).Decode(v) 13 } 14 15 func encodeXML(ctx *fasthttp.RequestCtx, v any) error { 16 return xml.NewEncoder(ctx).Encode(v) 17 } 18 19 func init() { 20 mediaType := "application/xml" 21 alias := "text/xml" 22 23 encoding.RegisterDecoder(decodeXML, mediaType, alias) 24 encoding.RegisterEncoder(encodeXML, mediaType, alias) 25 }