From 6da48b8b76eec5864510b6cdbeb5398a5ca3ce97 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sat, 27 Nov 2021 18:56:22 -0500 Subject: feed: add `get` HTTP GETs raw feed from Feed.Source --- feed/feed.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'feed') diff --git a/feed/feed.go b/feed/feed.go index cf4526b..109de5e 100644 --- a/feed/feed.go +++ b/feed/feed.go @@ -5,6 +5,8 @@ package feed import ( "fmt" + "io" + "net/http" "os" "path" ) @@ -54,3 +56,29 @@ func (feed *Feed) Validate(baseDumpDir string) error { return nil } + +// Get the feed. +func (feed *Feed) get() ([]byte, error) { + // Init byte container to store feed content. + bs := make([]byte, 0) + + resp, err := http.Get(feed.Source) + if err != nil { + return bs, err + } + + // Slurp body. + chunk := make([]byte, 100) + for { + c, err := resp.Body.Read(chunk) + if c < 1 { + break + } + if err != nil && err != io.EOF { + return bs, err + } + bs = append(bs, chunk[0:c]...) + } + return bs, nil +} + -- cgit v1.2.3