From 8c7f74594d75788c793d5d76b62aa0bf6a0c05c5 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Jul 2019 23:47:55 -0400 Subject: [PATCH] Make variables in getNewMessages() more generally descriptive, and (hopefully) finally fix the function so it restarts the api-listen command when it dies --- chatIn.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/chatIn.go b/chatIn.go index ba0150e..d72a365 100644 --- a/chatIn.go +++ b/chatIn.go @@ -149,16 +149,15 @@ func createFiltersString(channels []Channel) string { // Get new messages coming into keybase and send them into the channel func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) { - execCommand := []string{"chat", "api-listen"} + execString := []string{"chat", "api-listen"} if len(execOptions) > 0 { - execCommand = append(execCommand, execOptions...) + execString = append(execString, execOptions...) } - keybaseListen := exec.Command(k.Path, execCommand...) - keybaseOutput, _ := keybaseListen.StdoutPipe() - for { - keybaseListen.Start() - scanner := bufio.NewScanner(keybaseOutput) + execCmd := exec.Command(k.Path, execString...) + stdOut, _ := execCmd.StdoutPipe() + execCmd.Start() + scanner := bufio.NewScanner(stdOut) go func(scanner *bufio.Scanner, c chan<- ChatIn) { var jsonData ChatIn for scanner.Scan() { @@ -166,7 +165,7 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) { c <- jsonData } }(scanner, c) - keybaseListen.Wait() + execCmd.Wait() } }