Leverage ioutil.ReadAll() and ioutil.ReadFile() to simplify logic
Related to: #46
This commit is contained in:
+7
-14
@@ -16,7 +16,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -58,24 +58,17 @@ func init() {
|
|||||||
|
|
||||||
if len(args) > 1 && command == "" {
|
if len(args) > 1 && command == "" {
|
||||||
commandFile := args[1]
|
commandFile := args[1]
|
||||||
buf := new(bytes.Buffer)
|
var buf []byte
|
||||||
|
var err error
|
||||||
if commandFile == "-" {
|
if commandFile == "-" {
|
||||||
_, err := buf.ReadFrom(os.Stdin)
|
buf, err = ioutil.ReadAll(os.Stdin)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
file, err := os.Open(commandFile)
|
buf, err = ioutil.ReadFile(commandFile)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer file.Close()
|
command = string(buf)
|
||||||
_, err = buf.ReadFrom(file)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
command = buf.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.AddRoute(controlURL, urlPattern, method, entrypoint, command, os.Stdout); err != nil {
|
if err := client.AddRoute(controlURL, urlPattern, method, entrypoint, command, os.Stdout); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user