Leverage ioutil.ReadAll() and ioutil.ReadFile() to simplify logic

Related to: #46
This commit is contained in:
pancho horrillo
2019-10-23 17:55:20 +02:00
parent 7674725658
commit ae3bd76434
+9 -16
View File
@@ -16,7 +16,7 @@
package cmd
import (
"bytes"
"io/ioutil"
"log"
"os"
@@ -58,24 +58,17 @@ func init() {
if len(args) > 1 && command == "" {
commandFile := args[1]
buf := new(bytes.Buffer)
var buf []byte
var err error
if commandFile == "-" {
_, err := buf.ReadFrom(os.Stdin)
if err != nil {
log.Fatal(err)
}
buf, err = ioutil.ReadAll(os.Stdin)
} else {
file, err := os.Open(commandFile)
if err != nil {
log.Fatal(err)
}
defer file.Close()
_, err = buf.ReadFrom(file)
if err != nil {
log.Fatal(err)
}
buf, err = ioutil.ReadFile(commandFile)
}
command = buf.String()
if err != nil {
log.Fatal(err)
}
command = string(buf)
}
if err := client.AddRoute(controlURL, urlPattern, method, entrypoint, command, os.Stdout); err != nil {