Пример #1
0
func main() {
	flag.Parse()

	log.Println("Medium Story Watcher Started...")

	client := gohubbub.NewClient("http://medium.superfeedr.com", *host, *port, "Test App")
	client.Subscribe("https://medium.com/feed/latest", func(contentType string, body []byte) {
		var feed Feed
		xmlError := xml.Unmarshal(body, &feed)

		if xmlError != nil {
			log.Printf("XML Parse Error %v", xmlError)

		} else {
			for _, entry := range feed.Entries {
				log.Printf("%s by %s (%s)", entry.Title, entry.Author.Name, entry.URL)
			}
		}
	})

	go client.StartServer()

	time.Sleep(time.Second * 5)
	log.Println("Press Enter for graceful shutdown...")

	var input string
	fmt.Scanln(&input)

	client.Unsubscribe("https://medium.com/feed/latest")

	time.Sleep(time.Second * 5)
}
Пример #2
0
func main() {
	flag.Parse()

	log.Println("PubSubHubbub Subscriber Started")

	client := gohubbub.NewClient("http://pubsubhubbub.superfeedr.com", *host, *port, "Test App")
	client.Subscribe("http://push-pub.appspot.com/feed", func(contentType string, body []byte) {
		var feed Feed
		xmlError := xml.Unmarshal(body, &feed)

		if xmlError != nil {
			log.Printf("XML Parse Error %v", xmlError)

		} else {
			log.Println(feed.Status)
			for _, entry := range feed.Entries {
				log.Printf("%s - %s (%s)", entry.Title, entry.Content, entry.URL)
			}
		}
	})

	go client.StartServer()

	time.Sleep(time.Second * 5)
	log.Println("Press Enter for graceful shutdown...")

	var input string
	fmt.Scanln(&input)

	client.Unsubscribe("http://push-pub.appspot.com/feed")

	time.Sleep(time.Second * 5)
}