-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.go
More file actions
45 lines (34 loc) · 813 Bytes
/
Copy pathevents.go
File metadata and controls
45 lines (34 loc) · 813 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"net/http"
"github.com/AdminXVII/go-sse"
)
type Event struct {
Name string
Msg string
}
func main() {
// Create the server.
s := sse.NewServer(&sse.Options{
Headers: map[string]string {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Allow-Headers": "Keep-Alive,Cache-Control,Content-Type",
},
})
defer s.Shutdown()
unix, tcp := Listeners()
// Create tasks channel
msgs := make(chan Event, 100)
go Tasker(unix, msgs)
go func(){
for msg := range msgs {
s.SendMessage("", sse.NewMessage("", msg.Msg, msg.Name))
}
}()
// Register with endpoint.
http.Handle("/", s)
// Launch server
log.Fatal("Fatal error: ", http.Serve(tcp, nil))
}