https://github.com/andrewstuart/go-sse
A golang sse client.
https://github.com/andrewstuart/go-sse
golang server-sent-events sse
Last synced: 10 months ago
JSON representation
A golang sse client.
- Host: GitHub
- URL: https://github.com/andrewstuart/go-sse
- Owner: andrewstuart
- License: mit
- Created: 2015-09-02T03:26:23.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-09-23T15:39:23.000Z (over 4 years ago)
- Last Synced: 2025-08-13T16:16:12.539Z (10 months ago)
- Topics: golang, server-sent-events, sse
- Language: Go
- Size: 12.7 KB
- Stars: 14
- Watchers: 2
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/astuart.co/go-sse)
# sse
--
import "astuart.co/go-sse"
## Usage
```go
var Client = &http.Client{}
```
Client is the default client used for requests.
```go
var (
//ErrNilChan will be returned by Notify if it is passed a nil channel
ErrNilChan = fmt.Errorf("nil channel given")
)
```
```go
var GetReq = func(verb, uri string, body io.Reader) (*http.Request, error) {
return http.NewRequest(verb, uri, body)
}
```
GetReq is a function to return a single request. It will be used by notify to
get a request and can be replaces if additional configuration is desired on the
request. The "Accept" header will necessarily be overwritten.
#### func Notify
```go
func Notify(uri string, evCh chan<- *Event) error
```
Notify takes the uri of an SSE stream and channel, and will send an Event down
the channel when recieved, until the stream is closed. It will then close the
stream. This is blocking, and so you will likely want to call this in a new
goroutine (via `go Notify(..)`)
#### type Event
```go
type Event struct {
URI string
Type string
Data io.Reader
}
```
Event is a go representation of an http server-sent event