Documentation ¶
Overview ¶
Package sseclient is the client of server side events
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrClientNil = errors.New("sse: client is nil") ErrReqNil = errors.New("sse: req is nil") ErrChanNil = errors.New("sse: channel is nil") )
Errors
Functions ¶
This section is empty.
Types ¶
type CancelFunc ¶
type CancelFunc func()
CancelFunc is the function use for cancel notify
func Notify ¶
Notify does a request and notify to given channel when receive event CancelFunc use to close response body and channel Do not manually close channel
Example ¶
req, err := http.NewRequest(http.MethodGet, "https://dinosaur-facts.firebaseio.com/dinosaurs.json", nil) if err != nil { log.Fatal(err) } client := &http.Client{} eventChan := make(chan *Event) cancel, err := Notify(client, req, eventChan) if err != nil { log.Fatal(err) } go func() { // cancel after 10 seconds passed time.Sleep(10 * time.Second) cancel() }() for event := range eventChan { log.Printf("%s: %s", event.Type, string(event.Data)) }
Output:
Click to show internal directories.
Click to hide internal directories.