Adjust gitignore
parent
377667bf79
commit
e5702ff469
|
@ -1,4 +1,3 @@
|
|||
service
|
||||
# ---> Go
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -11,6 +12,8 @@ import (
|
|||
"git.kettek.net/accord/service/internal/version"
|
||||
)
|
||||
|
||||
var startMsg StartMessage
|
||||
|
||||
func main() {
|
||||
// Read config.
|
||||
cfg.Init()
|
||||
|
@ -22,7 +25,6 @@ func main() {
|
|||
var jsonEncoder *json.Encoder
|
||||
|
||||
stat, _ := os.Stdin.Stat()
|
||||
var startMsg StartMessage
|
||||
if (stat.Mode() & os.ModeCharDevice) == 0 {
|
||||
dec := json.NewDecoder(os.Stdin)
|
||||
dec.Decode(&startMsg)
|
||||
|
@ -31,11 +33,15 @@ func main() {
|
|||
if !startMsg.EnableJSON {
|
||||
fmt.Println("No EnableJSON message received, starting as stand-alone service.")
|
||||
fmt.Printf(" Git Id: %s\n", version.GitCommitId)
|
||||
go consoleReadLoop(os.Stdin, quitChannel, readChannel)
|
||||
} else {
|
||||
jsonEncoder = json.NewEncoder(os.Stdout)
|
||||
jsonEncoder.Encode(VersionMessage{
|
||||
GitCommitId: version.GitCommitId,
|
||||
})
|
||||
if startMsg.NewlineFlush {
|
||||
fmt.Fprintf(os.Stdout, "\n")
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Starting in bi-directional JSON mode")
|
||||
|
||||
// Start our STDIN read loop
|
||||
|
@ -45,7 +51,8 @@ func main() {
|
|||
}
|
||||
|
||||
// Begin waiting for data on our channels.
|
||||
for {
|
||||
done := false
|
||||
for !done {
|
||||
select {
|
||||
case msg := <-readChannel:
|
||||
fmt.Fprintf(os.Stderr, "%+v\n", msg)
|
||||
|
@ -54,6 +61,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Quitting\n")
|
||||
done = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +72,8 @@ type AMessage struct{}
|
|||
|
||||
// StartMessage is a bogus message for enabling JSON mode
|
||||
type StartMessage struct {
|
||||
EnableJSON bool `json:"enableJSON"`
|
||||
EnableJSON bool `json:"enableJSON"`
|
||||
NewlineFlush bool `json:"newlineFlush"`
|
||||
}
|
||||
|
||||
// VersionMessage is a message sent to the frontend immediately after JSON mode has been initiated.
|
||||
|
@ -89,3 +98,18 @@ func readLoop(reader io.Reader, quitChannel chan error, readChannel chan AMessag
|
|||
readChannel <- msg
|
||||
}
|
||||
}
|
||||
|
||||
func consoleReadLoop(r io.Reader, quitChannel chan error, readChannel chan AMessage) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
v := scanner.Text()
|
||||
err := scanner.Err()
|
||||
if err != nil {
|
||||
quitChannel <- err
|
||||
break
|
||||
} else if v == "quit" {
|
||||
quitChannel <- nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue