1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

testing executing commands

This commit is contained in:
postmannen 2021-01-25 16:50:21 +01:00
parent 5af0224b29
commit 360089081d
2 changed files with 17 additions and 2 deletions

View file

@ -32,6 +32,8 @@ type Message struct {
// The Unique ID of the message
ID int
// The actual data in the message
// TODO: Change this to a slice instead...or maybe use an
// interface type here to handle several data types ?
Data string
// The type of the message being sent
MessageType messageType
@ -54,7 +56,7 @@ func main() {
for {
m := Message{
ID: counter,
Data: "just some data",
Data: "ls",
}
var buf bytes.Buffer

View file

@ -5,6 +5,8 @@ import (
"encoding/gob"
"fmt"
"log"
"os"
"os/exec"
"github.com/nats-io/nats.go"
)
@ -72,6 +74,17 @@ func main() {
// Do some further processing of the actual data we received in the
// subscriber callback function.
for {
fmt.Printf("subcriber: received data = %#v\n", <-reqMsgCh)
msg := <-reqMsgCh
switch msg.MessageType {
case shellCommand:
cmd := exec.Command(msg.Data, "-l")
cmd.Stdout = os.Stdout
err := cmd.Start()
if err != nil {
fmt.Printf("error: execution of command failed: %v\n", err)
}
}
}
}