-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
34 lines (26 loc) · 614 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"log"
"net/http"
"github.com/gorilla/pat"
"github.com/ian-kent/goose"
)
var stream *goose.EventStream
func main() {
stream = goose.NewEventStream()
p := pat.New()
p.Path("/events").Methods("GET").HandlerFunc(handler)
p.Path("/notify").Methods("GET").HandlerFunc(someEvent)
http.Handle("/", p)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
func someEvent(w http.ResponseWriter, req *http.Request) {
stream.Notify("data", []byte("Hi!"))
w.WriteHeader(200)
}
func handler(w http.ResponseWriter, req *http.Request) {
stream.AddReceiver(w)
}