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
- Host: GitHub
- URL: https://github.com/mdigger/sse
- Owner: mdigger
- License: mit
- Created: 2017-08-11T18:15:24.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-20T06:27:28.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T05:12:24.585Z (almost 2 years ago)
- Topics: event-source, event-source-server, sse
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mdigger/sse
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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))
```