golang:generic_net_fetch:first_commit

This commit is contained in:
Logen Kain 2017-09-21 20:20:15 -07:00
parent 2a69b3160c
commit e628c534de
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1 @@
Get a real name

View File

@ -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)
}