From 521b1620077b184de65a501c7e7623f7edc79589 Mon Sep 17 00:00:00 2001 From: nytpu Date: Wed, 17 Mar 2021 09:15:14 -0600 Subject: [PATCH] implement sort.Interface for core.Feed --- core/structs.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/structs.go b/core/structs.go index a97fc74..6595100 100644 --- a/core/structs.go +++ b/core/structs.go @@ -92,6 +92,24 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) { return new, nil } +// Implement sort.Interface for Feed + +// Len returns the length of Items. +func (f *Feed) Len() int { + return len(f.Items) +} + +// Less compares Published of Items[i], Items[k] and returns true if Items[i] is +// before Items[j]. +func (f *Feed) Less(i, j int) { + return f.Items[i].Published.Before(f.Items[j].Published) +} + +// Swap swaps Items[i] and Items[j]. +func (f *Feed) Swap(i, j int) { + f.Items[i], f.Items[j] = f.Items[j], f.Items[i] +} + // Lock locks both feed and page mutexes. func (j *jsonData) Lock() { j.feedsMu.Lock()