[Solved] go multiple-value in single-value context


The channel can only take one variable so you are right that you need to define a structure to hold you results, however, you are not actually using this to pass into your channel. You have two options, either modify executeCmd to return a results:

func executeCmd(command, port string, hostname string, config *ssh.ClientConfig) results {

...
  return results{
    target: hostname, 
    output: strings.Split(stdoutBuf.String(), " "),
  }
}

ch <- executeCmd(cmd, port, hostname, config)

Or leave executeCmd as it is and put the values returned into a struct after calling it:

func executeCmd(command, port string, hostname string, config *ssh.ClientConfig) (target string, splitOut []string) {

...
  return hostname, strings.Split(stdoutBuf.String(), " ")
}

hostname, output := executeCmd(cmd, port, hostname, config)
result := results{
  target: hostname, 
  output: strings.Split(stdoutBuf.String(), " "),
}
ch <- result

solved go multiple-value in single-value context