404710eaa45fcb6ac1731ce1808110e18594c3c4
BenchmarkResponseWriter 1239 1304 +5.25% BenchmarkFullSSE 1469 915 -37.71% BenchmarkNoRetrySSE 1187 785 -33.87% BenchmarkSimpleSSE 961 687 -28.51% benchmark old allocs new allocs delta BenchmarkResponseWriter 9 9 +0.00% BenchmarkFullSSE 12 3 -75.00% BenchmarkNoRetrySSE 11 2 -81.82% BenchmarkSimpleSSE 8 2 -75.00% benchmark old bytes new bytes delta BenchmarkResponseWriter 442 442 +0.00% BenchmarkFullSSE 462 320 -30.74% BenchmarkNoRetrySSE 473 337 -28.75% BenchmarkSimpleSSE 426 314 -26.29%
Server-sent events (SSE) is a technology where a browser receives automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is standardized as part of HTML5[1] by the W3C.
- Real world demostration using Gin
- Read this great SSE introduction by the HTML5Rocks guys
- Browser support
##Sample code
import "github.com/manucorporat/sse"
func httpHandler(w http.ResponseWriter, req *http.Request) {
// data can be a primitive like a string, an integer or a float
sse.Encode(w, sse.Event{
Event: "message",
Data: "some data\nmore data",
})
// also a complex type, like a map, a struct or a slice
sse.Encode(w, sse.Event{
Id: "124",
Event: "message",
Data: map[string]interface{}{
"user": "manu",
"date": time.Now().Unix(),
"content": "hi!",
},
})
}
event: message
data: some data\\nmore data
id: 124
event: message
data: {"content":"hi!","date":1431540810,"user":"manu"}
##Content-Type
fmt.Println(sse.ContentType)
text/event-stream
##Decoding support
There is a client-side implementation of SSE coming soon.
Description
Languages
Go
100%