/catbird

A simple and robust Go websocket connection hub

Primary LanguageGoApache License 2.0Apache-2.0

Go Reference

CatBird

A simple and robust Go websocket connection hub.

hub, _ := catbird.New(catbird.Config{Secret: secret})
defer hub.Stop()

// ...

mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
    hub.HandleWebsocket(w, r, r.Context().Value("user").(string), []string{"clock"})
})

// ...

ticker := time.NewTicker(time.Second)
defer ticker.Stop()

go func() {
    for {
        select {
        case t := <-ticker.C:
            hub.SendString("clock", fmt.Println("Current time", t))
        }
    }
}()

http.ListenAndServe("localhost:3000", mux)

Install

go get -u github.com/ugent-library/catbird