From 04e37a8257d0021a593b9c8977fd3f5a9dee271c Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Thu, 3 May 2018 07:22:32 +0200 Subject: [PATCH] Add cast checks around in-reply-to --- cmd/server/memory.go | 13 ++++++++----- pkg/feedbin/feeds.go | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/server/memory.go b/cmd/server/memory.go index 4eb6d95..8f0ff65 100644 --- a/cmd/server/memory.go +++ b/cmd/server/memory.go @@ -281,11 +281,14 @@ func mapToItem(result map[string]interface{}) microsub.Item { } if value, e := result["in-reply-to"]; e { - for _, v := range value.([]interface{}) { - if replyTo, ok := v.(string); ok { - item.InReplyTo = append(item.InReplyTo, replyTo) - } else if cite, ok := v.(map[string]interface{}); ok { - item.InReplyTo = append(item.InReplyTo, cite["url"].(string)) + if replyTo, ok := value.(string); ok { + } else if replyTo, ok := value.([]interface{}); ok { + for _, v := range value.([]interface{}) { + if replyTo, ok := v.(string); ok { + item.InReplyTo = append(item.InReplyTo, replyTo) + } else if cite, ok := v.(map[string]interface{}); ok { + item.InReplyTo = append(item.InReplyTo, cite["url"].(string)) + } } } } diff --git a/pkg/feedbin/feeds.go b/pkg/feedbin/feeds.go index ddb01e1..c1d9fcc 100644 --- a/pkg/feedbin/feeds.go +++ b/pkg/feedbin/feeds.go @@ -5,11 +5,13 @@ import ( "fmt" ) +// Feedbin is the main object for calling the Feedbin API type Feedbin struct { user string password string } +// New returns a new Feedbin object with the provided user and password func New(user, password string) *Feedbin { var fb Feedbin fb.user = user @@ -17,6 +19,7 @@ func New(user, password string) *Feedbin { return &fb } +// Taggings returns taggings func (fb *Feedbin) Taggings() ([]Tagging, error) { resp, err := fb.get("/v2/taggings.json") if err != nil { @@ -32,6 +35,7 @@ func (fb *Feedbin) Taggings() ([]Tagging, error) { return taggings, nil } +// Feed returns a Feed for id func (fb *Feedbin) Feed(id int64) (Feed, error) { resp, err := fb.get(fmt.Sprintf("/v2/feeds/%d.json", id)) if err != nil { @@ -48,6 +52,7 @@ func (fb *Feedbin) Feed(id int64) (Feed, error) { return feed, nil } +// Entries return a slice of entries func (fb *Feedbin) Entries() ([]Entry, error) { resp, err := fb.get("/v2/entries.json") if err != nil {