This commit is contained in:
parent
3b8ada2852
commit
0d1d391f2a
|
@ -23,6 +23,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"p83.nl/go/ekster/pkg/microsub"
|
"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)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
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 {
|
} else {
|
||||||
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)
|
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 500)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user