# HG changeset patch # User Sascha L. Teichmann # Date 1589191068 -7200 # Node ID c4e295b2d6a378a93780aba1afc671a4a738e573 # Parent 23addd19a6e2dc33122778438c68001e237e8f93 Some code simplification. diff -r 23addd19a6e2 -r c4e295b2d6a3 pkg/common/errors.go --- a/pkg/common/errors.go Mon May 11 11:41:57 2020 +0200 +++ b/pkg/common/errors.go Mon May 11 11:57:48 2020 +0200 @@ -30,3 +30,15 @@ } return errors.New(b.String()) } + +// JoinErrors creates a comma separated string out of the given errors. +func JoinErrors(errors []error) string { + var b strings.Builder + for _, err := range errors { + if b.Len() > 0 { + b.WriteString(", ") + } + b.WriteString(err.Error()) + } + return b.String() +} diff -r 23addd19a6e2 -r c4e295b2d6a3 pkg/controllers/stretches.go --- a/pkg/controllers/stretches.go Mon May 11 11:41:57 2020 +0200 +++ b/pkg/controllers/stretches.go Mon May 11 11:57:48 2020 +0200 @@ -22,7 +22,6 @@ "log" "net/http" "runtime" - "strings" "sync" "time" @@ -293,7 +292,7 @@ if len(loaded) == 0 { http.Error( rw, - fmt.Sprintf("No bottleneck loaded: %v", joinErrors(errors)), + fmt.Sprintf("No bottleneck loaded: %v", common.JoinErrors(errors)), http.StatusInternalServerError, ) return @@ -428,17 +427,6 @@ } } -func joinErrors(errors []error) string { - var b strings.Builder - for _, err := range errors { - if b.Len() > 0 { - b.WriteString(", ") - } - b.WriteString(err.Error()) - } - return b.String() -} - func stretchAvailabilty(rw http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) @@ -541,7 +529,7 @@ if len(loaded) == 0 { http.Error( rw, - fmt.Sprintf("No bottleneck loaded: %v", joinErrors(errors)), + fmt.Sprintf("No bottleneck loaded: %v", common.JoinErrors(errors)), http.StatusInternalServerError, ) return