Skip to content

Instantly share code, notes, and snippets.

@clipperhouse
Created September 21, 2013 18:05
Show Gist options
  • Save clipperhouse/6652758 to your computer and use it in GitHub Desktop.
Save clipperhouse/6652758 to your computer and use it in GitHub Desktop.
[go-pkg-rss] Why are item.Title’s not coming back?
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