func ExampleHandler() { http.Handle("/events", eventsource.Handler(func(lastID string, e *eventsource.Encoder, stop <-chan bool) { for { select { case <-time.After(200 * time.Millisecond): e.Encode(eventsource.Event{Data: []byte("tick")}) case <-stop: return } } })) }
func ExampleHandler_ServeHTTP() { es := eventsource.Handler(func(lastID string, e *eventsource.Encoder, stop <-chan bool) { for { select { case <-time.After(200 * time.Millisecond): e.Encode(eventsource.Event{Data: []byte("tick")}) case <-stop: return } } }) http.HandleFunc("/events", func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("Authorization") == "" { w.WriteHeader(http.StatusUnauthorized) return } es.ServeHTTP(w, r) }) }