39 lines
819 B
Go
39 lines
819 B
Go
|
package xml
|
||
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"io"
|
||
|
"sync"
|
||
|
)
|
||
|
|
||
|
const awsDefaultNamespace = "http://s3.amazonaws.com/doc/2006-03-01/"
|
||
|
|
||
|
type DecoderProvider struct {
|
||
|
mu sync.RWMutex
|
||
|
defaultXMLNSForCompleteMultipart bool
|
||
|
}
|
||
|
|
||
|
func NewDecoderProvider(defaultNamespace bool) *DecoderProvider {
|
||
|
return &DecoderProvider{
|
||
|
defaultXMLNSForCompleteMultipart: defaultNamespace,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (d *DecoderProvider) NewCompleteMultipartDecoder(r io.Reader) *xml.Decoder {
|
||
|
dec := xml.NewDecoder(r)
|
||
|
|
||
|
d.mu.RLock()
|
||
|
if d.defaultXMLNSForCompleteMultipart {
|
||
|
dec.DefaultSpace = awsDefaultNamespace
|
||
|
}
|
||
|
d.mu.RUnlock()
|
||
|
|
||
|
return dec
|
||
|
}
|
||
|
|
||
|
func (d *DecoderProvider) UseDefaultNamespaceForCompleteMultipart(useDefaultNamespace bool) {
|
||
|
d.mu.Lock()
|
||
|
d.defaultXMLNSForCompleteMultipart = useDefaultNamespace
|
||
|
d.mu.Unlock()
|
||
|
}
|