diff options
Diffstat (limited to 'cmd/dolmetschctl/dolmetschctl.go')
-rw-r--r-- | cmd/dolmetschctl/dolmetschctl.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/cmd/dolmetschctl/dolmetschctl.go b/cmd/dolmetschctl/dolmetschctl.go index a1598bc..1d8c6ad 100644 --- a/cmd/dolmetschctl/dolmetschctl.go +++ b/cmd/dolmetschctl/dolmetschctl.go @@ -25,10 +25,26 @@ package main import ( "log" "os" + "time" + "github.com/gorilla/websocket" "spreadspace.org/dolmetschctl/pkg/controller" + // "spreadspace.org/dolmetschctl/pkg/types" ) +func run(c *controller.Controller, ws *websocket.Conn) error { + ch := make(chan controller.Event, 100) + c.Subscribe(ch) + + for { + select { + case ev := <-ch: + log.Printf("got controller event: %v", ev) + } + } + return nil +} + func main() { log.Println("hello world.") @@ -43,14 +59,19 @@ func main() { log.Printf("Error initializeing the controller: %v", err) os.Exit(1) } - log.Printf("controller successfully initialized!") - ch := make(chan controller.Event, 100) - c.Subscribe(ch) for { - ev := <-ch - log.Printf("got controller event: %v", ev) + ws, _, err := websocket.DefaultDialer.Dial("ws://127.0.0.1:8234/api/v1/socket", nil) + if err != nil { + log.Printf("Error connecting to daemon: %v", err) + } else { + + err := run(c, ws) + log.Printf("run() returned: %v", err) + } + log.Printf("will retry in one second...") + time.Sleep(time.Second) } log.Printf("exiting.") |