GolongpollGolang HTTP 的 longpolling 库
Golongpoll 是 golang HTTP 的 longpolling 库,可以使构建 web pub-sub 更加容易。
基本用法:
import "github.com/jcuga/golongpoll"
// This launches a goroutine and creates channels for all the plumbing
manager, err := golongpoll.CreateManager()
// Expose events to browsers
// See subsection on how to interact with the subscription handler
http.HandleFunc("/events", manager.SubscriptionHandler)
http.ListenAndServe("127.0.0.1:8081", nil)
// Pass the manager around or create closures and publish:
manager.Publish("subscription-category", "Some data. Can be string or any obj convertable to JSON")
manager.Publish("different-category", "More data")评论
