-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_marshal_test.go
102 lines (95 loc) · 2.99 KB
/
example_marshal_test.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) VirtualTam
// SPDX-License-Identifier: MIT
package opml_test
import (
"fmt"
"os"
"github.com/virtualtam/opml-go"
)
func ExampleMarshal() {
document := opml.Document{
Version: "2.0",
Head: opml.Head{
Title: "Feed subscriptions",
OwnerName: "Jane Doe",
OwnerEmail: "jane@thedo.es",
},
Body: opml.Body{
Outlines: []opml.Outline{
{
Text: "Linux",
Title: "Linux",
Outlines: []opml.Outline{
{
Type: opml.OutlineTypeSubscription,
Text: "Bits from Debian",
Title: "Bits from Debian",
HtmlUrl: "https://bits.debian.org/feeds/atom.xml",
XmlUrl: "https://bits.debian.org/feeds/atom.xml",
},
{
Type: opml.OutlineTypeSubscription,
Text: "KXStudio News",
Title: "KXStudio News",
HtmlUrl: "https://kx.studio/News",
XmlUrl: "https://kx.studio/News/?action=feed",
},
},
},
{
Text: "Social News",
Title: "Social News",
Outlines: []opml.Outline{
{
Type: opml.OutlineTypeSubscription,
Text: "Hacker News",
Title: "Hacker News",
HtmlUrl: "https://news.ycombinator.com/",
XmlUrl: "https://news.ycombinator.com/rss",
},
{
Type: opml.OutlineTypeSubscription,
Text: "Lobsters",
Title: "Lobsters",
HtmlUrl: "https://lobste.rs",
XmlUrl: "https://lobste.rs/rss",
},
{
Type: opml.OutlineTypeSubscription,
Text: "Phoronix",
Title: "Phoronix",
HtmlUrl: "https://www.phoronix.com/",
XmlUrl: "https://www.phoronix.com/rss.php",
},
},
},
},
},
}
m, err := opml.Marshal(&document)
if err != nil {
fmt.Println("failed to marshal data as XML:", err)
os.Exit(1)
}
fmt.Print(string(m))
// Output:
// <?xml version="1.0" encoding="UTF-8"?>
// <opml version="2.0">
// <head>
// <title>Feed subscriptions</title>
// <ownerName>Jane Doe</ownerName>
// <ownerEmail>jane@thedo.es</ownerEmail>
// </head>
// <body>
// <outline text="Linux" title="Linux">
// <outline text="Bits from Debian" htmlUrl="https://bits.debian.org/feeds/atom.xml" title="Bits from Debian" type="rss" xmlUrl="https://bits.debian.org/feeds/atom.xml"></outline>
// <outline text="KXStudio News" htmlUrl="https://kx.studio/News" title="KXStudio News" type="rss" xmlUrl="https://kx.studio/News/?action=feed"></outline>
// </outline>
// <outline text="Social News" title="Social News">
// <outline text="Hacker News" htmlUrl="https://news.ycombinator.com/" title="Hacker News" type="rss" xmlUrl="https://news.ycombinator.com/rss"></outline>
// <outline text="Lobsters" htmlUrl="https://lobste.rs" title="Lobsters" type="rss" xmlUrl="https://lobste.rs/rss"></outline>
// <outline text="Phoronix" htmlUrl="https://www.phoronix.com/" title="Phoronix" type="rss" xmlUrl="https://www.phoronix.com/rss.php"></outline>
// </outline>
// </body>
// </opml>
}