golang:generic_net_fetch:first_commit
This commit is contained in:
parent
2a69b3160c
commit
e628c534de
1
go/generic_net_fetch/TODO
Normal file
1
go/generic_net_fetch/TODO
Normal file
@ -0,0 +1 @@
|
||||
Get a real name
|
44
go/generic_net_fetch/main.go
Normal file
44
go/generic_net_fetch/main.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user