https://github.com/cristalhq/sse
Server-Sent Events (SSE) library for Go
https://github.com/cristalhq/sse
dependency-free go golang server-sent-events sse streaming
Last synced: over 1 year ago
JSON representation
Server-Sent Events (SSE) library for Go
- Host: GitHub
- URL: https://github.com/cristalhq/sse
- Owner: cristalhq
- License: mit
- Created: 2019-11-09T20:02:54.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T16:18:10.000Z (over 2 years ago)
- Last Synced: 2025-03-23T03:24:49.588Z (over 1 year ago)
- Topics: dependency-free, go, golang, server-sent-events, sse, streaming
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sse
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]
Server-Sent Events (SSE) library for Go.
See https://www.w3.org/TR/eventsource for the technical specification.
## Features
* Simple API.
* Performant.
* Dependency-free.
* Low-level API to build a server.
## Install
Go version 1.13
```
go get github.com/cristalhq/sse
```
## Example
As a simple HTTP handler:
```go
http.HandleFunc("/sse", func(w http.ResponseWriter, r *http.Request) {
stream, err := sse.UpgradeHTTP(r, w)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
data := struct {
Text string `json:"text"`
}{
Text: "hey there",
}
stream.WriteJSON("123", "msg", data)
})
```
See [example_test.go](https://github.com/cristalhq/sse/blob/master/example_test.go) for more.
## Documentation
See [these docs][pkg-url].
## License
[MIT License](LICENSE).
[build-img]: https://github.com/cristalhq/sse/workflows/build/badge.svg
[build-url]: https://github.com/cristalhq/sse/actions
[pkg-img]: https://pkg.go.dev/badge/cristalhq/sse
[pkg-url]: https://pkg.go.dev/github.com/cristalhq/sse
[reportcard-img]: https://goreportcard.com/badge/cristalhq/sse
[reportcard-url]: https://goreportcard.com/report/cristalhq/sse
[coverage-img]: https://codecov.io/gh/cristalhq/sse/branch/master/graph/badge.svg
[coverage-url]: https://codecov.io/gh/cristalhq/sse