1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-12 16:58:36 +00:00

Improve OPML package to be more idiomatic

This commit is contained in:
Frédéric Guillot 2017-11-20 19:11:06 -08:00
parent e91a9b4f13
commit c26787f476
7 changed files with 50 additions and 40 deletions

View file

@ -17,13 +17,13 @@ func Serialize(subscriptions SubcriptionList) string {
writer := bufio.NewWriter(&b)
writer.WriteString(xml.Header)
opml := new(Opml)
opml.Version = "2.0"
feeds := new(opml)
feeds.Version = "2.0"
for categoryName, subs := range groupSubscriptionsByFeed(subscriptions) {
outline := Outline{Text: categoryName}
category := outline{Text: categoryName}
for _, subscription := range subs {
outline.Outlines = append(outline.Outlines, Outline{
category.Outlines = append(category.Outlines, outline{
Title: subscription.Title,
Text: subscription.Title,
FeedURL: subscription.FeedURL,
@ -31,12 +31,12 @@ func Serialize(subscriptions SubcriptionList) string {
})
}
opml.Outlines = append(opml.Outlines, outline)
feeds.Outlines = append(feeds.Outlines, category)
}
encoder := xml.NewEncoder(writer)
encoder.Indent(" ", " ")
if err := encoder.Encode(opml); err != nil {
if err := encoder.Encode(feeds); err != nil {
log.Println(err)
return ""
}