From e09288f9f7a460c8364f4b2f8acc5529889bd79e Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Fri, 5 Mar 2021 20:36:56 +0100 Subject: [PATCH] refactor: Removing concat error to use httputils one Signed-off-by: Vincent Boutour --- pkg/service/ketchup/ketchup.go | 5 ++--- pkg/service/repository/repository.go | 3 +-- pkg/service/service.go | 20 -------------------- pkg/service/user/user.go | 3 +-- 4 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 pkg/service/service.go diff --git a/pkg/service/ketchup/ketchup.go b/pkg/service/ketchup/ketchup.go index cfd5b664..c7653768 100644 --- a/pkg/service/ketchup/ketchup.go +++ b/pkg/service/ketchup/ketchup.go @@ -10,7 +10,6 @@ import ( httpModel "github.com/ViBiOh/httputils/v4/pkg/model" "github.com/ViBiOh/ketchup/pkg/model" "github.com/ViBiOh/ketchup/pkg/semver" - "github.com/ViBiOh/ketchup/pkg/service" "github.com/ViBiOh/ketchup/pkg/service/repository" "github.com/ViBiOh/ketchup/pkg/store/ketchup" ) @@ -156,7 +155,7 @@ func (a app) check(ctx context.Context, old, new model.Ketchup) error { } if new.Repository.ID == 0 && new.User.ID == 0 { - return service.ConcatError(output) + return httpModel.ConcatError(output) } if len(strings.TrimSpace(new.Pattern)) == 0 { @@ -178,7 +177,7 @@ func (a app) check(ctx context.Context, old, new model.Ketchup) error { } } - return service.ConcatError(output) + return httpModel.ConcatError(output) } func enrichKetchupsWithSemver(list []model.Ketchup) []model.Ketchup { diff --git a/pkg/service/repository/repository.go b/pkg/service/repository/repository.go index 94c0d695..ae120404 100644 --- a/pkg/service/repository/repository.go +++ b/pkg/service/repository/repository.go @@ -12,7 +12,6 @@ import ( "github.com/ViBiOh/ketchup/pkg/helm" "github.com/ViBiOh/ketchup/pkg/model" "github.com/ViBiOh/ketchup/pkg/semver" - "github.com/ViBiOh/ketchup/pkg/service" "github.com/ViBiOh/ketchup/pkg/store/repository" ) @@ -194,7 +193,7 @@ func (a app) check(ctx context.Context, old, new model.Repository) error { output = append(output, errors.New("name already exists")) } - return service.ConcatError(output) + return httpModel.ConcatError(output) } func (a app) LatestVersions(repo model.Repository) (map[string]semver.Version, error) { diff --git a/pkg/service/service.go b/pkg/service/service.go deleted file mode 100644 index 0fb612a0..00000000 --- a/pkg/service/service.go +++ /dev/null @@ -1,20 +0,0 @@ -package service - -import ( - "errors" - "strings" -) - -// ConcatError concat errors to a single string -func ConcatError(errs []error) error { - if len(errs) == 0 { - return nil - } - - values := make([]string, len(errs)) - for index, err := range errs { - values[index] = err.Error() - } - - return errors.New(strings.Join(values, ", ")) -} diff --git a/pkg/service/user/user.go b/pkg/service/user/user.go index d1249610..a128e6af 100644 --- a/pkg/service/user/user.go +++ b/pkg/service/user/user.go @@ -11,7 +11,6 @@ import ( "github.com/ViBiOh/httputils/v4/pkg/logger" httpModel "github.com/ViBiOh/httputils/v4/pkg/model" "github.com/ViBiOh/ketchup/pkg/model" - "github.com/ViBiOh/ketchup/pkg/service" "github.com/ViBiOh/ketchup/pkg/store/user" ) @@ -102,5 +101,5 @@ func (a app) check(ctx context.Context, _, new model.User) error { output = append(output, errors.New("email already used")) } - return service.ConcatError(output) + return httpModel.ConcatError(output) }