Documentation ¶
Overview ¶
Package sse provides HTML5 Server-Sent Events for Go.
See http://www.w3.org/TR/eventsource/ for the technical specification.
Example ¶
package main import ( "fmt" "log" "net/http" "time" "github.com/mdigger/sse" ) func main() { type Event struct { ID int `json:"id"` Time time.Time `json:"time"` } var sse = new(sse.Server) go func() { var id int for range time.Tick(5 * time.Second) { id++ _ = sse.Event(fmt.Sprintf("%04d", id), "event", &Event{ ID: id, Time: time.Now().Truncate(time.Second), }) } }() http.Handle("/events", sse) log.Fatal(http.ListenAndServe(":8000", nil)) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides HTML5 Server-Sent Events
func (*Server) Event ¶
Event sends an event with the given data encoded as JSON to all connected clients.
Click to show internal directories.
Click to hide internal directories.