Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 816 Bytes

README.md

File metadata and controls

38 lines (27 loc) · 816 Bytes

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