From 62102871230d11f1bc23a0c689d452625b019636 Mon Sep 17 00:00:00 2001 From: w1ndyb0y Date: Mon, 21 Dec 2020 17:59:15 +0800 Subject: [PATCH] add socket server --- cmd/start.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index a57af46..5c610e6 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -66,7 +66,7 @@ func start(cmd *cobra.Command, args []string) { // `signal.Notify` registers the given channel to // receive notifications of the specified signals. signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - run = true + utils.ServerRunning = true // This goroutine executes a blocking receive for // signals. When it gets one it'll print it out @@ -83,7 +83,9 @@ func start(cmd *cobra.Command, args []string) { // expected signal (as indicated by the goroutine // above sending a value on `done`) and then exit. fmt.Println("awaiting signal") - for run { + _ = utils.InitDb(dbFile, dbInit) + utils.Listen(socketAddress) + for utils.ServerRunning { if !utils.IsPortOpen() { log.Println("try to open port") err := utils.OpenPort(device, baudrate, bytesize)