An open API service indexing awesome lists of open source software.

https://github.com/mdigger/sse

HTML5 Server-Sent Events for Go
https://github.com/mdigger/sse

event-source event-source-server sse

Last synced: 5 months ago
JSON representation

HTML5 Server-Sent Events for Go

Awesome Lists containing this project

README

          

# HTML5 Server-Sent Events for Go

See http://www.w3.org/TR/eventsource/ for the technical specification.

```golang
import "github.com/mdigger/sse"

var sse = new(sse.Server)

type Event struct {
ID int `json:"id"`
Time time.Time `json:"time"`
}

go func() {
var id int
for range time.Tick(5 * time.Second) {
id++
sse.Event(fmt.Sprintf("%04d", id), "event",
&Event{
ID: id,
Time: time.Now().Truncate(time.Second),
})
}
}()

http.Handle("/events", sse)
log.Fatal(http.ListenAndServe(":8000", nil))
```