[#187] sdk: Implement IsSupportedVersion function

Implement function that checks the compatibility of the specified version
with the current NeoFS revision.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-03 11:29:41 +03:00 committed by Alex Vanin
parent 352e99d9b9
commit 89a7a946dc
2 changed files with 50 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/pkg/errors"
)
// Version represents v2-compatible version.
@ -65,3 +66,19 @@ func (v *Version) ToV2() *refs.Version {
func (v *Version) String() string {
return fmt.Sprintf("v%d.%d", v.GetMajor(), v.GetMinor())
}
// IsSupportedVersion returns error if v is not supported by current SDK.
func IsSupportedVersion(v *Version) error {
switch mjr := v.GetMajor(); mjr {
case 2:
switch mnr := v.GetMinor(); mnr {
case 0:
return nil
}
}
return errors.Errorf("unsupported version %d.%d",
v.GetMajor(),
v.GetMinor(),
)
}