Created
September 21, 2013 18:05
-
-
Save clipperhouse/6652758 to your computer and use it in GitHub Desktop.
[go-pkg-rss] Why are item.Title’s not coming back?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
rss "github.com/jteeuwen/go-pkg-rss" | |
"net/http" | |
"os" | |
) | |
var items []*rss.Item | |
var channels []*rss.Channel | |
func hello(w http.ResponseWriter, r *http.Request) { | |
feed := rss.New(5, true, chanHandler, itemHandler) | |
url := "http://stackoverflow.com/feeds" | |
feed.Fetch(url, nil) | |
fmt.Printf("Sent fetch for %s\n", url) | |
fmt.Fprintf(w, "There are %d items in %s\n\n", len(items), url) | |
for key, value := range items { | |
fmt.Fprintf(w, "%d: %s\n\n", key, value.Title) | |
} | |
} | |
func main() { | |
http.HandleFunc("/", hello) | |
http.ListenAndServe(":"+os.Getenv("PORT"), nil) | |
} | |
func chanHandler(feed *rss.Feed, newchannels []*rss.Channel) { | |
channels = newchannels | |
} | |
func itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) { | |
items = newitems | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment