summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctl/dolmetschctl.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-13 22:51:18 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-13 22:51:28 +0100
commit9f81f0c1b6f24246e2ce60ce9bde5a92e7b7451a (patch)
tree1da382ac1722b96eafd3aa95cdfebcb89bb6091f /cmd/dolmetschctl/dolmetschctl.go
parentadded state change subscription to state machine (diff)
move common types to own package
Diffstat (limited to 'cmd/dolmetschctl/dolmetschctl.go')
-rw-r--r--cmd/dolmetschctl/dolmetschctl.go31
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.")