Make variables in getNewMessages() more generally descriptive, and (hopefully) finally fix the function so it restarts the api-listen command when it dies
This commit is contained in:
15
chatIn.go
15
chatIn.go
@ -149,16 +149,15 @@ func createFiltersString(channels []Channel) string {
|
|||||||
|
|
||||||
// Get new messages coming into keybase and send them into the channel
|
// Get new messages coming into keybase and send them into the channel
|
||||||
func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
|
func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
|
||||||
execCommand := []string{"chat", "api-listen"}
|
execString := []string{"chat", "api-listen"}
|
||||||
if len(execOptions) > 0 {
|
if len(execOptions) > 0 {
|
||||||
execCommand = append(execCommand, execOptions...)
|
execString = append(execString, execOptions...)
|
||||||
}
|
}
|
||||||
keybaseListen := exec.Command(k.Path, execCommand...)
|
|
||||||
keybaseOutput, _ := keybaseListen.StdoutPipe()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
keybaseListen.Start()
|
execCmd := exec.Command(k.Path, execString...)
|
||||||
scanner := bufio.NewScanner(keybaseOutput)
|
stdOut, _ := execCmd.StdoutPipe()
|
||||||
|
execCmd.Start()
|
||||||
|
scanner := bufio.NewScanner(stdOut)
|
||||||
go func(scanner *bufio.Scanner, c chan<- ChatIn) {
|
go func(scanner *bufio.Scanner, c chan<- ChatIn) {
|
||||||
var jsonData ChatIn
|
var jsonData ChatIn
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
@ -166,7 +165,7 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
|
|||||||
c <- jsonData
|
c <- jsonData
|
||||||
}
|
}
|
||||||
}(scanner, c)
|
}(scanner, c)
|
||||||
keybaseListen.Wait()
|
execCmd.Wait()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user