-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer_xml.go
29 lines (23 loc) · 829 Bytes
/
writer_xml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package emissione
import (
"encoding/xml"
)
// NewXmlWriter creates a new SimpleWriter, marshalling via xml.Marshal.
func NewXmlWriter(options ...WriterOption) Writer {
defaults := []WriterOption{
ContentType("application/xml;charset=utf-8"),
MarshallMethod(xml.Marshal),
}
return NewSimpleWriter(append(defaults, options...)...)
}
// NewXmlIndentWriter creates a new SimpleWriter, marshalling via xml.MarshalIndent.
func NewXmlIndentWriter(prefix string, indent string, options ...WriterOption) Writer {
defaults := []WriterOption{
ContentType("application/xml;charset=utf-8"),
// Define a custom marshall method, which uses MarshalIndent
MarshallMethod(func(v interface{}) ([]byte, error) {
return xml.MarshalIndent(v, prefix, indent)
}),
}
return NewSimpleWriter(append(defaults, options...)...)
}