From 12e97da0c17814ecf1a4c262973936c14f15b41b Mon Sep 17 00:00:00 2001 From: bruceauyeung Date: Fri, 2 Dec 2016 11:23:30 +0800 Subject: [PATCH] use bytes.Buffer instead of append for error string concat Signed-off-by: bruceauyeung --- cmd/kubeadm/app/preflight/checks.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 432cba29399..1a0c344e155 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -18,7 +18,7 @@ package preflight import ( "bufio" - "errors" + "bytes" "fmt" "io" "net" @@ -182,7 +182,7 @@ func (fac FileAvailableCheck) Check() (warnings, errors []error) { 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 { executable string mandatory bool @@ -359,16 +359,14 @@ func RunChecks(checks []PreFlightCheck, ww io.Writer) error { for _, w := range warnings { io.WriteString(ww, fmt.Sprintf("[preflight] WARNING: %s\n", w)) } - for _, e := range errs { - found = append(found, e) - } + found = append(found, errs...) } if len(found) > 0 { - errs := "" + var errs bytes.Buffer 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 }