gorots: admin: add support for sending an optional payload along with the command

master
S.J.R. van Schaik 7 years ago
parent ba4a9b22f0
commit e611220f47
  1. 24
      admin/main.go
  2. 11
      admin/tbm.go

@ -26,8 +26,8 @@ var (
}
)
func cmd_generic(tbm *TBM, command string, args []string) error {
cmd := &Command{command, args}
func cmd_generic(tbm *TBM, command string, args []string, payload []byte) error {
cmd := &Command{command, args, payload}
tbm.Commands <- cmd
res := <-tbm.Results
@ -40,43 +40,43 @@ func cmd_generic(tbm *TBM, command string, args []string) error {
}
func cmd_ls(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs ls", args)
return cmd_generic(tbm, "mufs ls", args, nil)
}
func cmd_cat(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs cat", args)
return cmd_generic(tbm, "mufs cat", args, nil)
}
func cmd_stat(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs stat", args)
return cmd_generic(tbm, "mufs stat", args, nil)
}
func cmd_cp(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs cp", args)
return cmd_generic(tbm, "mufs cp", args, nil)
}
func cmd_rm(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs rm", args)
return cmd_generic(tbm, "mufs rm", args, nil)
}
func cmd_mkdir(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs mkdir", args)
return cmd_generic(tbm, "mufs mkdir", args, nil)
}
func cmd_rmdir(tbm *TBM, args []string) error {
return cmd_generic(tbm, "mufs rmdir", args)
return cmd_generic(tbm, "mufs rmdir", args, nil)
}
func cmd_date(tbm *TBM, args []string) error {
return cmd_generic(tbm, "date", args)
return cmd_generic(tbm, "date", args, nil)
}
func cmd_set_date(tbm *TBM, args []string) error {
return cmd_generic(tbm, "set-date", args)
return cmd_generic(tbm, "set-date", args, nil)
}
func cmd_time(tbm *TBM, args []string) error {
return cmd_generic(tbm, "time", args)
return cmd_generic(tbm, "time", args, nil)
}
func main() {

@ -18,6 +18,7 @@ type TBM struct {
type Command struct {
command string
args []string
payload []byte
}
type Result struct {
@ -124,7 +125,7 @@ func handleResults(in io.Reader, c chan *Result) {
}
}
func serialise(out io.Writer, command string, args []string) error {
func serialise(out io.Writer, command string, args []string, payload []byte) error {
var quoted_args []string
quoted_args = append(quoted_args, command)
@ -137,7 +138,11 @@ func serialise(out io.Writer, command string, args []string) error {
output := []byte(out_string)
output = append(output, '\r')
//output = append(output, 0x4)
if payload != nil {
output = append(output, payload...)
output = append(output, 0x4)
}
_, err := out.Write(output)
// err is non nil if n != len(output)
@ -150,7 +155,7 @@ func serialise(out io.Writer, command string, args []string) error {
func handleCommands(out io.Writer, c chan *Command) {
for command := range c {
err := serialise(out, command.command, command.args)
err := serialise(out, command.command, command.args, command.payload)
if err != nil {
log.Fatal(err)
}

Loading…
Cancel
Save