-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml.go
41 lines (35 loc) · 849 Bytes
/
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
30
31
32
33
34
35
36
37
38
39
40
41
package encoding
import (
"polyapi/internal/encoding/xml"
)
//-------------------------
// ToXml encode a Go data to xml string.
func ToXml(v interface{}, pretty bool) (string, error) {
enc := xml.Encoder{}
b, err := enc.Encode(v, nil, pretty)
return unsafeByteString(b), err
}
// MustToXml encode a Go data to xml string.
// It panic if error.
func MustToXml(v interface{}, pretty bool) string {
s, err := ToXml(v, pretty)
if err != nil {
panic(err)
}
return s
}
// FromXml decode a xml string to universal Go data.
func FromXml(s string) (interface{}, error) {
dec := xml.Decoder{}
d, err := dec.Decode(unsafeStringBytes(s))
return d, err
}
// MustFromXml decode a xml string to universal Go data.
// It panic if error.
func MustFromXml(s string) interface{} {
d, err := FromXml(s)
if err != nil {
panic(err)
}
return d
}