-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 928 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
35
36
37
38
39
40
41
42
package main
import (
"go-command-pattern/bus"
"go-command-pattern/http"
"go-command-pattern/service/alert"
"go-command-pattern/service/input"
"go-command-pattern/service/notification"
)
var inputChannel = make(chan bus.Event)
var simpleStdoutChannel = make(chan bus.Event)
var shinyStdoutChannel = make(chan bus.Event)
func subscribe() {
busInstance := bus.GetInstance()
// we can have topics that send to multiple channels
busInstance.Subscribe("input", inputChannel)
busInstance.Subscribe("input", simpleStdoutChannel)
busInstance.Subscribe("notify", simpleStdoutChannel)
busInstance.Subscribe("alert", shinyStdoutChannel)
}
func runRouter() {
for {
select {
case d := <-inputChannel:
go input.Process(d)
case d := <-simpleStdoutChannel:
go notification.Process(d)
case d := <-shinyStdoutChannel:
go alert.Process(d)
}
}
}
func main() {
go http.InitServer()
subscribe()
runRouter()
}