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