From 3604137c2728d155eec71514052248076f4b154a Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 27 Nov 2021 18:59:40 -0500 Subject: feed: add unmarshal Unmarshals the feed and sets Feed.Object --- feed/feed.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/feed/feed.go b/feed/feed.go index 3f82096..631783b 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -87,6 +87,28 @@ func (feed *Feed) get() ([]byte, error) { } +// Unmarshal raw feed into an object. +func (feed *Feed) unmarshal(bs []byte) error { + var err error + + // Unmarshal based on feed's schema type. + switch { + case feed.Schema == "npr": + feed.Object, err = nprUnmarshal(bs) + if err != nil { + return err + } + return nil + case feed.Schema == "youtube": + feed.Object, err = youtubeUnmarshal(bs) + if err != nil { + return err + } + return nil + } + return fmt.Errorf("schema of feed '%s' unknown", feed.Id) +} + // Unmarshal a NPR feed. func nprUnmarshal(bs []byte) (schema.NPRFeed, error) { nprFeed := new(schema.NPRFeed) -- cgit v1.2.3