SSE Over QUIC
Implementation of Server Sent Events by QUIC. A faster replacement for traditional SSE over HTTP/2.
Installation
go get github.com/snapp-incubator/qsse
Basic Usage
// Client
import "github.com/snapp-incubator/qsse"
func main() {
_, err := qsse.NewClient("localhost:4242", "secret", []string{"firstnames", "lastnames"})
if err != nil {
panic(err)
}
select {}
}
// Server
import (
"github.com/snapp-incubator/qsse"
"log"
"math/rand"
"time"
)
var firstNames = []string{...}
var lastNames = []string{...}
func main() {
authenticateFunc := func(token string) bool {
log.Printf("Authenticating token: %s", token)
return token == "secret"
}
topics := []string{"firstnames", "lastnames"}
server, err := qsse.NewServer("localhost:4242", qsse.GetDefaultTLSConfig(), topics)
if err != nil {
panic(err)
}
server.SetAuthenticationFunc(authenticateFunc)
go func() {
for {
if rand.NormFloat64() > 0.5 {
server.PublishEvent("firstnames", []byte(firstNames[rand.Intn(len(firstNames))]))
} else {
server.PublishEvent("lastnames", []byte(lastNames[rand.Intn(len(lastNames))]))
}
<-time.After(2 * time.Second)
}
}()
select {}
}