use bytes.Buffer instead of append for error string concat

Signed-off-by: bruceauyeung <ouyang.qinhua@zte.com.cn>
This commit is contained in:
bruceauyeung 2016-12-02 11:23:30 +08:00
parent 3f7b000496
commit 12e97da0c1

View File

@ -18,7 +18,7 @@ package preflight
import ( import (
"bufio" "bufio"
"errors" "bytes"
"fmt" "fmt"
"io" "io"
"net" "net"
@ -182,7 +182,7 @@ func (fac FileAvailableCheck) Check() (warnings, errors []error) {
return nil, errors return nil, errors
} }
// InPathChecks checks if the given executable is present in the path. // InPathCheck checks if the given executable is present in the path.
type InPathCheck struct { type InPathCheck struct {
executable string executable string
mandatory bool mandatory bool
@ -359,16 +359,14 @@ func RunChecks(checks []PreFlightCheck, ww io.Writer) error {
for _, w := range warnings { for _, w := range warnings {
io.WriteString(ww, fmt.Sprintf("[preflight] WARNING: %s\n", w)) io.WriteString(ww, fmt.Sprintf("[preflight] WARNING: %s\n", w))
} }
for _, e := range errs { found = append(found, errs...)
found = append(found, e)
}
} }
if len(found) > 0 { if len(found) > 0 {
errs := "" var errs bytes.Buffer
for _, i := range found { for _, i := range found {
errs += "\t" + i.Error() + "\n" errs.WriteString("\t" + i.Error() + "\n")
} }
return &PreFlightError{Msg: errors.New(errs).Error()} return &PreFlightError{Msg: errs.String()}
} }
return nil return nil
} }