-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
49 lines (40 loc) · 921 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
43
44
45
46
47
48
49
package main
import (
"fmt"
"log"
"os"
"reflect"
"github.com/hedonhermdev/go-psql-msg/config"
"github.com/hedonhermdev/go-psql-msg/db"
)
func main() {
conf_file, err := os.Open("config.yaml")
if err != nil {
log.Fatal("Could not open config file")
}
conf, err := config.ParseConfig(conf_file)
if err != nil {
log.Fatal("Could not parse config from config.yaml")
}
events := make(chan db.Event)
errors := make(chan error)
if len(conf.Channels) == 0 {
log.Fatal("No channels to listen on. Exiting...")
}
for _, chName := range conf.Channels {
fmt.Printf("Listening on channel %s...\n", chName)
l := db.NewJSONListener(conf.Database)
go l.Listen(chName, events, errors)
}
for {
select {
case err := <-errors:
log.Print(err)
case event := <-events:
fmt.Printf("%+v\n", event)
for k, v := range event.Data {
fmt.Printf("%s: %v\n", k, reflect.TypeOf(v))
}
}
}
}