diff --git a/.docker/.gitkeep b/.docker/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/pkg/api.go b/pkg/api.go index 935eb5c..739ba4e 100644 --- a/pkg/api.go +++ b/pkg/api.go @@ -63,8 +63,10 @@ func (api Api) Get(idx *Index, format Format) http.HandlerFunc { // refreshes the index by removing all entries, and fetching the feed. func (api Api) Refresh(idx *Index) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + tempUrls := make([]Url, len(idx.Urls)) + copy(tempUrls, idx.Urls) idx.Clear() - for _, url := range idx.Urls { + for _, url := range tempUrls { log.Printf("refreshing: %s", url.Url) err := idx.Add(url.Url, url.Category) if err != nil { diff --git a/pkg/index.go b/pkg/index.go index e67d564..762cd1f 100644 --- a/pkg/index.go +++ b/pkg/index.go @@ -23,11 +23,7 @@ func (idx *Index) Add(url string, category string) error { item.parentFeed = &feed idx.Rank = insertSorted(idx.Rank, &item) } - idx.Urls = append(idx.Urls, struct { - Url string - Category string - Size int - }{url, category, len(feed.Channel.Items)}) + idx.Urls = append(idx.Urls, Url{url, category, len(feed.Channel.Items)}) log.Printf("added to feed: '%s' %v", url, category) } return err @@ -88,9 +84,10 @@ func (idx *Index) Serve(port string) { log.Fatal(http.ListenAndServe(port, nil)) } -// removes all entries from rank. +// removes all entries from rank, return copy of urls for re-create. func (idx *Index) Clear() { idx.Rank = nil + idx.Urls = nil } // initiate rss feed index class (enforce singleton?) diff --git a/pkg/types.go b/pkg/types.go index c94d9c1..20e66ce 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -44,13 +44,15 @@ type Feed struct { Url string } +type Url struct { + Url string + Category string + Size int +} + type Index struct { Rank []*Item - Urls []struct { - Url string - Category string - Size int - } + Urls []Url } type Query struct {