go-sse: github.com/sietseringers/go-sse Index | Files

package sse

import "github.com/sietseringers/go-sse"

Index

Package Files

sse.go

Variables

var (
    //ErrNilChan will be returned by Notify if it is passed a nil channel
    ErrNilChan = fmt.Errorf("nil channel given")

    //Client is the default client used for requests.
    Client = &http.Client{}

    //Logger is used to log debug messages. By default logging is disabled;
    //to enable, use SetOutput() or overwrite this instance.
    Logger = log.New(ioutil.Discard, "", log.LstdFlags)
)
var GetReq = func(ctx context.Context, verb, uri string) (*http.Request, error) {
    return http.NewRequestWithContext(ctx, verb, uri, nil)
}

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 Uses

func Notify(ctx context.Context, uri string, retry bool, evCh chan<- *Event) (err error)

Notify takes the uri of an SSE stream and channel, and will send an Event down the channel when received, 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 Uses

type Event struct {
    URI  string
    ID   string
    Type string
    Data []byte
}

Event is a go representation of an http server-sent event

Package sse imports 11 packages (graph) and is imported by 2 packages. Updated 2020-11-24. Refresh now. Tools for package owners.