Microsub events test
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2018-09-08 17:49:20 +02:00
parent 3b8ada2852
commit 0d1d391f2a
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -23,6 +23,7 @@ import (
"log"
"net/http"
"os"
"time"
"p83.nl/go/ekster/pkg/microsub"
@ -133,6 +134,27 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), 500)
return
}
} else if action == "events" {
w.Header().Add("Content-Type", "text/event-stream")
c := make(chan string)
go func() {
c <- "test"
time.Sleep(10 * time.Second)
c <- "test"
time.Sleep(10 * time.Second)
c <- "test"
time.Sleep(10 * time.Second)
c <- "test"
time.Sleep(10 * time.Second)
c <- "end"
}()
for t := range c {
fmt.Fprintln(w, `event: ping`)
fmt.Fprintf(w, `event: %s\n`, t)
fmt.Fprintln(w)
}
} else {
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)
return