orbiter/api/events.go
Gianluca Arbezzano 1709cf5150 Event stream
2017-02-24 00:16:28 +00:00

21 lines
434 B
Go

package api
import (
"fmt"
"net/http"
"github.com/Sirupsen/logrus"
)
func Events(eventChannel chan *logrus.Entry) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
logrus.Info("New events")
flusher, _ := w.(http.Flusher)
for {
e := <-eventChannel
fmt.Fprintf(w, "Ciao %d\n", e.Message)
flusher.Flush() // Trigger "chunked" encoding and send a chunk...
}
}
}