Skip to content

Commit

Permalink
use standard errors.Join since we already use go1.22
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Abdelrahman <[email protected]>
  • Loading branch information
MustafaSaber committed Aug 27, 2024
1 parent 2c39d54 commit 00ff742
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
15 changes: 0 additions & 15 deletions dataclients/kubernetes/definitions/definitions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package definitions

import (
"strings"
"time"

"errors"
Expand Down Expand Up @@ -44,17 +43,3 @@ type WeightedBackend interface {
GetName() string
GetWeight() float64
}

// TODO: use https://pkg.go.dev/errors#Join with go1.21
func errorsJoin(errs ...error) error {
var errVals []string
for _, err := range errs {
if err != nil {
errVals = append(errVals, err.Error())
}
}
if len(errVals) > 0 {
return errors.New(strings.Join(errVals, "\n"))
}
return nil
}
3 changes: 2 additions & 1 deletion dataclients/kubernetes/definitions/ingressvalidator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package definitions

import (
"errors"
"fmt"

"github.com/zalando/skipper/eskip"
Expand All @@ -15,7 +16,7 @@ func (igv *IngressV1Validator) Validate(item *IngressV1Item) error {
errs = append(errs, igv.validatePredicateAnnotation(item.Metadata.Annotations))
errs = append(errs, igv.validateRoutesAnnotation(item.Metadata.Annotations))

return errorsJoin(errs...)
return errors.Join(errs...)
}

func (igv *IngressV1Validator) validateFilterAnnotation(annotations map[string]string) error {
Expand Down
12 changes: 6 additions & 6 deletions dataclients/kubernetes/definitions/routegroupvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ValidateRouteGroups(rgl *RouteGroupList) error {
for _, rg := range rgl.Items {
errs = append(errs, defaultRouteGroupValidator.Validate(rg))
}
return errorsJoin(errs...)
return errors.Join(errs...)
}

func (rgv *RouteGroupValidator) Validate(item *RouteGroupItem) error {
Expand All @@ -41,7 +41,7 @@ func (rgv *RouteGroupValidator) Validate(item *RouteGroupItem) error {
errs = append(errs, rgv.validateBackends(item))
errs = append(errs, rgv.validateHosts(item))

return errorsJoin(errs...)
return errors.Join(errs...)
}

// TODO: we need to pass namespace/name in all errors
Expand Down Expand Up @@ -76,7 +76,7 @@ func (rgv *RouteGroupValidator) validateFilters(item *RouteGroupItem) error {
}
}

return errorsJoin(errs...)
return errors.Join(errs...)
}

func (rgv *RouteGroupValidator) validatePredicates(item *RouteGroupItem) error {
Expand All @@ -91,7 +91,7 @@ func (rgv *RouteGroupValidator) validatePredicates(item *RouteGroupItem) error {
}
}
}
return errorsJoin(errs...)
return errors.Join(errs...)
}

func (rgv *RouteGroupValidator) validateBackends(item *RouteGroupItem) error {
Expand All @@ -108,7 +108,7 @@ func (rgv *RouteGroupValidator) validateBackends(item *RouteGroupItem) error {
}
}
}
return errorsJoin(errs...)
return errors.Join(errs...)
}

func (rgv *RouteGroupValidator) validateHosts(item *RouteGroupItem) error {
Expand All @@ -120,7 +120,7 @@ func (rgv *RouteGroupValidator) validateHosts(item *RouteGroupItem) error {
}
uniqueHosts[host] = struct{}{}
}
return errorsJoin(errs...)
return errors.Join(errs...)
}

// TODO: we need to pass namespace/name in all errors
Expand Down

0 comments on commit 00ff742

Please sign in to comment.