Skip to content

Commit c73a51b

Browse files
committed
Make Feed keep and expose a reference to the original feed object
Call Feed.OriginalFeed() to get the original feed if available.
1 parent 1a928bd commit c73a51b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

feed.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,27 @@ type Feed struct {
3636
Items []*Item `json:"items"`
3737
FeedType string `json:"feedType"`
3838
FeedVersion string `json:"feedVersion"`
39+
40+
originalFeed interface{}
3941
}
4042

4143
func (f Feed) String() string {
4244
json, _ := json.MarshalIndent(f, "", " ")
4345
return string(json)
4446
}
4547

48+
// OriginalFeed returns the source feed object if
49+
// this Feed was translated from an RSS, Atom, or
50+
// json feed type by the default translators, else
51+
// it returns null. This provides access to
52+
// feed-specific fields and features at
53+
// translation time, but the original feed data is
54+
// not preserved through a
55+
// serialization/deserialization cycle.
56+
func (f Feed) OriginalFeed() interface{} {
57+
return f.originalFeed
58+
}
59+
4660
// Item is the universal Item type that atom.Entry
4761
// and rss.Item gets translated to. It represents
4862
// a single entry in a given feed.

translator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (t *DefaultRSSTranslator) Translate(feed interface{}) (*Feed, error) {
3838
}
3939

4040
result := &Feed{}
41+
result.originalFeed = rss
4142
result.Title = t.translateFeedTitle(rss)
4243
result.Description = t.translateFeedDescription(rss)
4344
result.Link = t.translateFeedLink(rss)
@@ -543,6 +544,7 @@ func (t *DefaultAtomTranslator) Translate(feed interface{}) (*Feed, error) {
543544
}
544545

545546
result := &Feed{}
547+
result.originalFeed = atom
546548
result.Title = t.translateFeedTitle(atom)
547549
result.Description = t.translateFeedDescription(atom)
548550
result.Link = t.translateFeedLink(atom)
@@ -871,6 +873,7 @@ func (t *DefaultJSONTranslator) Translate(feed interface{}) (*Feed, error) {
871873
}
872874

873875
result := &Feed{}
876+
result.originalFeed = json
874877
result.FeedVersion = json.Version
875878
result.Title = t.translateFeedTitle(json)
876879
result.Link = t.translateFeedLink(json)

0 commit comments

Comments
 (0)