Mercurial > gemma
changeset 5207:c4e295b2d6a3 new-fwa
Some code simplification.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 May 2020 11:57:48 +0200 |
parents | 23addd19a6e2 |
children | defca5418446 |
files | pkg/common/errors.go pkg/controllers/stretches.go |
diffstat | 2 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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() +}
--- 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