-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.go
More file actions
89 lines (75 loc) · 2.11 KB
/
Copy pathfeed.go
File metadata and controls
89 lines (75 loc) · 2.11 KB
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
package main
import (
"encoding/xml"
"fmt"
"io"
"time"
)
type Feed struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
Generator *Generator `xml:"generator,omitempty"` // XXX: pointer to play nice with omitempty
Title string `xml:"title"`
ID string `xml:"id"`
Links []Link `xml:"link"`
Updated AtomTime `xml:"updated"`
Authors []Person `xml:"author"`
Entries []Entry `xml:"entry"`
}
type Entry struct {
Title string `xml:"title"`
ID string `xml:"id"`
Links []Link `xml:"link"`
Published AtomTime `xml:"published"`
Updated AtomTime `xml:"updated"`
Authors []Person `xml:"author"`
Categories []Category `xml:"category,omitempty"`
Summary string `xml:"summary,omitempty"`
Content *Content `xml:"content,omitempty"` // XXX: pointer to play nice with omitempty
}
type Generator struct {
URI string `xml:"uri,attr,omitempty"`
Version string `xml:"version,attr,omitempty"`
Name string `xml:",chardata"`
}
type Link struct {
Rel string `xml:"rel,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Href string `xml:"href,attr"`
}
type Person struct {
Name string `xml:"name"`
URI string `xml:"uri,omitempty"`
Email string `xml:"email,omitempty"`
}
type Category struct {
Term string `xml:"term,attr"`
Scheme string `xml:"scheme,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
}
type Content struct {
Type string `xml:"type,attr"`
Body string `xml:",chardata"`
}
type AtomTime time.Time
func (at *AtomTime) Compare(u AtomTime) int {
return time.Time(*at).Compare(time.Time(u))
}
func (at *AtomTime) Format(layout string) string {
return time.Time(*at).Format(layout)
}
func (at *AtomTime) MarshalText() ([]byte, error) {
return []byte(at.Format(time.RFC3339)), nil
}
func (feed *Feed) WriteXML(w io.Writer) error {
b, err := xml.MarshalIndent(feed, "", " ")
if err != nil {
return err
}
w.Write([]byte(xml.Header))
w.Write(b)
w.Write([]byte{'\n'})
return nil
}
func TagURI(tagger string, specific string) string {
return fmt.Sprintf("tag:%s:%s", tagger, specific)
}