File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Package eventsource is a library for dealing with server sent events in Go.
3+
4+ The library attempts to make as few assumptions as possible about how your apps
5+ will be written, and remains as generic as possible while still being simple and useful.
6+
7+ The three core obects to the library are Clients, Events, and Streams.
8+
9+ Client wraps an HTTP connection, and runs a worker routine to send events to the connected
10+ client in a thread-safe way. It gracefully handles client disconnects.
11+
12+ Event encapsulates all the data that can be sent with SSE, and contains the logic for converting
13+ it to wire format to send. Events are not thread-safe by themselves.
14+
15+ Stream is an abstraction for 0 or more Client connections, and adds some multiplexing and filtering
16+ on top of the Client. It also can act as an http.Handler to automatically register inbound client
17+ connections and disconnectinos.
18+
19+ A quick example of a simple sever that broadcasts a "tick" event every second
20+
21+ func main() {
22+ stream := &eventsource.Stream{}
23+ go func(s *eventsource.Stream) {
24+ for {
25+ time.Sleep(time.Second)
26+ stream.Broadcast(eventsource.DataEvent("tick"))
27+ }
28+ }(stream)
29+ http.ListenAndServe(":8080", stream)
30+ }
31+
32+ */
133package eventsource
234
335import (
You can’t perform that action at this time.
0 commit comments