要么我失去理智,要么我不理解指针数组,要么图书馆被破坏了。也许你可以帮忙。以下代码似乎可以很好地获取 Atom 项目,但查看它们的标题却是空字符串。
(这恰好是通过http实现的,我认为这不是问题,但当然一切皆有可能。)
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
}