Skip to content

Commit 5216f6b

Browse files
committed
Revert "Quick fixes (#239)"
This reverts commit 5305abb.
1 parent 5277f80 commit 5216f6b

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

feed.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Feed struct {
3838
FeedVersion string `json:"feedVersion"`
3939
}
4040

41-
// String returns a JSON representation of the Feed for debugging purposes.
4241
func (f Feed) String() string {
4342
json, _ := json.MarshalIndent(f, "", " ")
4443
return string(json)
@@ -98,19 +97,9 @@ func (f Feed) Len() int {
9897
// Less compares PublishedParsed of Items[i], Items[k]
9998
// and returns true if Items[i] is less than Items[k].
10099
func (f Feed) Less(i, k int) bool {
101-
iParsed := f.Items[i].PublishedParsed
102-
kParsed := f.Items[k].PublishedParsed
103-
104-
if iParsed == nil && kParsed == nil {
105-
return false
106-
}
107-
if iParsed == nil {
108-
return true
109-
}
110-
if kParsed == nil {
111-
return false
112-
}
113-
return iParsed.Before(*kParsed)
100+
return f.Items[i].PublishedParsed.Before(
101+
*f.Items[k].PublishedParsed,
102+
)
114103
}
115104

116105
// Swap swaps Items[i] and Items[k].

json/parser.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
jsoniter "github.com/json-iterator/go"
88
)
99

10+
var (
11+
j = jsoniter.ConfigCompatibleWithStandardLibrary
12+
)
1013

1114
// Parser is an JSON Feed Parser
1215
type Parser struct{}
@@ -18,7 +21,6 @@ func (ap *Parser) Parse(feed io.Reader) (*Feed, error) {
1821
buffer := new(bytes.Buffer)
1922
buffer.ReadFrom(feed)
2023

21-
j := jsoniter.ConfigCompatibleWithStandardLibrary
2224
err := j.Unmarshal(buffer.Bytes(), jsonFeed)
2325
if err != nil {
2426
return nil, err

parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type HTTPError struct {
2424
Status string
2525
}
2626

27-
// Error returns the string representation of the HTTP error.
2827
func (err HTTPError) Error() string {
2928
return fmt.Sprintf("http error: %s", err.Status)
3029
}
@@ -125,7 +124,8 @@ func (f *Parser) ParseURLWithContext(feedURL string, ctx context.Context) (feed
125124

126125
if resp != nil {
127126
defer func() {
128-
if ce := resp.Body.Close(); ce != nil && err == nil {
127+
ce := resp.Body.Close()
128+
if ce != nil {
129129
err = ce
130130
}
131131
}()

translator.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ func (t *DefaultRSSTranslator) translateFeedGenerator(rss *rss.Feed) (generator
257257
}
258258

259259
func (t *DefaultRSSTranslator) translateFeedCategories(rss *rss.Feed) (categories []string) {
260-
var cats []string
260+
cats := []string{}
261261
if rss.Categories != nil {
262-
cats = make([]string, 0, len(rss.Categories))
263262
for _, c := range rss.Categories {
264263
cats = append(cats, c.Value)
265264
}
@@ -291,7 +290,7 @@ func (t *DefaultRSSTranslator) translateFeedCategories(rss *rss.Feed) (categorie
291290
}
292291

293292
func (t *DefaultRSSTranslator) translateFeedItems(rss *rss.Feed) (items []*Item) {
294-
items = make([]*Item, 0, len(rss.Items))
293+
items = []*Item{}
295294
for _, i := range rss.Items {
296295
items = append(items, t.translateFeedItem(i))
297296
}
@@ -458,9 +457,8 @@ func firstImageFromHtmlDocument(document string) *Image {
458457
}
459458

460459
func (t *DefaultRSSTranslator) translateItemCategories(rssItem *rss.Item) (categories []string) {
461-
var cats []string
460+
cats := []string{}
462461
if rssItem.Categories != nil {
463-
cats = make([]string, 0, len(rssItem.Categories))
464462
for _, c := range rssItem.Categories {
465463
cats = append(cats, c.Value)
466464
}
@@ -641,7 +639,7 @@ func (t *DefaultAtomTranslator) translateFeedAuthor(atom *atom.Feed) (author *Pe
641639

642640
func (t *DefaultAtomTranslator) translateFeedAuthors(atom *atom.Feed) (authors []*Person) {
643641
if atom.Authors != nil {
644-
authors = make([]*Person, 0, len(atom.Authors))
642+
authors = []*Person{}
645643

646644
for _, a := range atom.Authors {
647645
authors = append(authors, &Person{
@@ -693,7 +691,7 @@ func (t *DefaultAtomTranslator) translateFeedGenerator(atom *atom.Feed) (generat
693691

694692
func (t *DefaultAtomTranslator) translateFeedCategories(atom *atom.Feed) (categories []string) {
695693
if atom.Categories != nil {
696-
categories = make([]string, 0, len(atom.Categories))
694+
categories = []string{}
697695
for _, c := range atom.Categories {
698696
if c.Label != "" {
699697
categories = append(categories, c.Label)
@@ -706,7 +704,7 @@ func (t *DefaultAtomTranslator) translateFeedCategories(atom *atom.Feed) (catego
706704
}
707705

708706
func (t *DefaultAtomTranslator) translateFeedItems(atom *atom.Feed) (items []*Item) {
709-
items = make([]*Item, 0, len(atom.Entries))
707+
items = []*Item{}
710708
for _, entry := range atom.Entries {
711709
items = append(items, t.translateFeedItem(entry))
712710
}
@@ -781,7 +779,7 @@ func (t *DefaultAtomTranslator) translateItemAuthor(entry *atom.Entry) (author *
781779

782780
func (t *DefaultAtomTranslator) translateItemAuthors(entry *atom.Entry) (authors []*Person) {
783781
if entry.Authors != nil {
784-
authors = make([]*Person, 0, len(entry.Authors))
782+
authors = []*Person{}
785783
for _, a := range entry.Authors {
786784
authors = append(authors, &Person{
787785
Name: a.Name,
@@ -802,7 +800,7 @@ func (t *DefaultAtomTranslator) translateItemImage(entry *atom.Entry) (image *Im
802800

803801
func (t *DefaultAtomTranslator) translateItemCategories(entry *atom.Entry) (categories []string) {
804802
if entry.Categories != nil {
805-
categories = make([]string, 0, len(entry.Categories))
803+
categories = []string{}
806804
for _, c := range entry.Categories {
807805
if c.Label != "" {
808806
categories = append(categories, c.Label)
@@ -816,7 +814,7 @@ func (t *DefaultAtomTranslator) translateItemCategories(entry *atom.Entry) (cate
816814

817815
func (t *DefaultAtomTranslator) translateItemEnclosures(entry *atom.Entry) (enclosures []*Enclosure) {
818816
if entry.Links != nil {
819-
enclosures = make([]*Enclosure, 0, len(entry.Links))
817+
enclosures = []*Enclosure{}
820818
for _, e := range entry.Links {
821819
if e.Rel == "enclosure" {
822820
enclosure := &Enclosure{}
@@ -1003,7 +1001,7 @@ func (t *DefaultJSONTranslator) translateFeedAuthor(json *json.Feed) (author *Pe
10031001

10041002
func (t *DefaultJSONTranslator) translateFeedAuthors(json *json.Feed) (authors []*Person) {
10051003
if json.Authors != nil {
1006-
authors = make([]*Person, 0, len(json.Authors))
1004+
authors = []*Person{}
10071005
for _, a := range json.Authors {
10081006
name, address := shared.ParseNameAddress(a.Name)
10091007
author := &Person{}
@@ -1036,7 +1034,7 @@ func (t *DefaultJSONTranslator) translateFeedImage(json *json.Feed) (image *Imag
10361034
}
10371035

10381036
func (t *DefaultJSONTranslator) translateFeedItems(json *json.Feed) (items []*Item) {
1039-
items = make([]*Item, 0, len(json.Items))
1037+
items = []*Item{}
10401038
for _, i := range json.Items {
10411039
items = append(items, t.translateFeedItem(i))
10421040
}
@@ -1128,7 +1126,7 @@ func (t *DefaultJSONTranslator) translateItemAuthor(jsonItem *json.Item) (author
11281126

11291127
func (t *DefaultJSONTranslator) translateItemAuthors(jsonItem *json.Item) (authors []*Person) {
11301128
if jsonItem.Authors != nil {
1131-
authors = make([]*Person, 0, len(jsonItem.Authors))
1129+
authors = []*Person{}
11321130
for _, a := range jsonItem.Authors {
11331131
name, address := shared.ParseNameAddress(a.Name)
11341132
author := &Person{}

0 commit comments

Comments
 (0)