From 9f81f0c1b6f24246e2ce60ce9bde5a92e7b7451a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 13 Feb 2019 22:51:18 +0100 Subject: move common types to own package --- cmd/dolmetschctl/dolmetschctl.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'cmd/dolmetschctl/dolmetschctl.go') 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.") -- cgit v1.2.3