diff options
author | siddharth <s@ricketyspace.net> | 2021-11-27 18:59:40 -0500 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2021-11-27 18:59:40 -0500 |
commit | 3604137c2728d155eec71514052248076f4b154a (patch) | |
tree | 7b0cb5c49969e5e3faddbb9d8a05d6fbaaa61f06 /feed | |
parent | 3047b9266833f61ad112fefc9169efd199daaa54 (diff) |
feed: add unmarshal
Unmarshals the feed and sets Feed.Object
Diffstat (limited to 'feed')
-rw-r--r-- | feed/feed.go | 22 |
1 files changed, 22 insertions, 0 deletions
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) |