Skip to content

Commit

Permalink
internal: move NewVersion() in FeatureTest() closer to where it is used
Browse files Browse the repository at this point in the history
Some feature tests are called in a loop, so this work can be avoided if there
is a cached result.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed Feb 18, 2022
1 parent 5a1354f commit 2fa712e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ type FeatureTestFn func() error
//
// Returns an error wrapping ErrNotSupported if the feature is not supported.
func FeatureTest(name, version string, fn FeatureTestFn) func() error {
v, err := NewVersion(version)
if err != nil {
return func() error { return err }
}

ft := new(featureTest)
return func() error {
ft.RLock()
Expand All @@ -79,6 +74,11 @@ func FeatureTest(name, version string, fn FeatureTestFn) func() error {
err := fn()
switch {
case errors.Is(err, ErrNotSupported):
v, err := NewVersion(version)
if err != nil {
return err
}

ft.result = &UnsupportedFeatureError{
MinimumVersion: v,
Name: name,
Expand Down

0 comments on commit 2fa712e

Please sign in to comment.