-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeed.go
53 lines (46 loc) · 1.2 KB
/
feed.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
package main
import (
"bytes"
"encoding/xml"
"log"
)
type Atom1 struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
Title string `xml:"title"`
Subtitle string `xml:"subtitle"`
Id string `xml:"id"`
Updated string `xml:"updated"`
Rights string `xml:"rights"`
Link Link `xml:"link"`
Author Author `xml:"author"`
EntryList []Entry `xml:"entry"`
}
type Link struct {
Href string `xml:"href,attr"`
}
type Author struct {
Name string `xml:"name"`
Email string `xml:"email"`
}
type Entry struct {
Title string `xml:"title"`
Summary string `xml:"summary"`
Content string `xml:"content"`
Id string `xml:"id"`
Published string `xml:"published"`
Updated string `xml:"updated"`
Link Link `xml:"link"`
Author Author `xml:"author"`
}
func parseAtom(content []byte) (Atom1, error) {
// Contents from Ptt will sometimes contain the escape character (\x1b),
// which will leads xml.Unmarshal to fail, so here we strip them first.
safeContent := bytes.Replace(content, []byte("\x1b"), []byte(""), -1)
a := Atom1{}
err := xml.Unmarshal(safeContent, &a)
if err != nil {
log.Println(err)
return Atom1{}, err
}
return a, nil
}