diff --git a/go/generic_net_fetch/TODO b/go/generic_net_fetch/TODO new file mode 100644 index 0000000..09caee3 --- /dev/null +++ b/go/generic_net_fetch/TODO @@ -0,0 +1 @@ +Get a real name diff --git a/go/generic_net_fetch/main.go b/go/generic_net_fetch/main.go new file mode 100644 index 0000000..213a888 --- /dev/null +++ b/go/generic_net_fetch/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os" + + "github.com/mmcdole/gofeed" +) + +func fileGet(filepath, url string) (err error) { + out, err := os.Create(filepath) + if err != nil { + return err + } + defer out.Close() + + resp, err := http.Get(url) + if err != nil { + return err + } + defer resp.Body.Close() + + _, err = io.Copy(out, resp.Body) + if err != nil { + return err + } + + return nil +} + +func main() { + feedParser := gofeed.NewParser() + feed, _ := feedParser.ParseURL("http://feeds.twit.tv/twit.xml") + + fileUrl := feed.Items[1].Enclosures[0].URL + fileTitle := feed.Items[1].Title + + fmt.Println(fileUrl) + fmt.Println(fileTitle) + + fileGet(fileTitle, fileUrl) +}