Chissel is an SSE (Sever Sent Events) provider and broker that can be used with almost any http mux/router
- Mux/router agnostic (provides single http handler func - works with stdlib mux, Chi, Gorilla etc.)
- Optional support for topics
- Optional support for multi-tenancy
- Optional authentication
- Pluggable logging
To install chissel, use go get:
go get github.com/go-andiamo/chissel
To update chissel to the latest version, run:
go get -u github.com/go-andiamo/chissel
The following example is a simple SSE chat using stdlib mux (see _examples/muxchat)
package main
import (
_ "embed"
"github.com/go-andiamo/chissel"
"io"
"log"
"net/http"
)
//go:embed index.html
var index []byte
func main() {
sse, err := chissel.NewSse()
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write(index)
})
mux.HandleFunc("POST /messages", func(w http.ResponseWriter, r *http.Request) {
if r.Body == nil {
return
}
data, _ := io.ReadAll(r.Body)
sse.Broadcast(chissel.Event{
Message: data,
})
})
mux.HandleFunc("GET /messages", sse.Handler())
_ = http.ListenAndServe(":8080", mux)
}