forked from TrueCloudLab/frostfs-api-go
[#140] sdk: Refactor version type
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
524280a5e8
commit
e0c34a51f2
7 changed files with 102 additions and 32 deletions
|
@ -6,23 +6,62 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
||||
type (
|
||||
Version struct {
|
||||
Major uint32
|
||||
Minor uint32
|
||||
}
|
||||
)
|
||||
// Version represents v2-compatible version.
|
||||
type Version refs.Version
|
||||
|
||||
var SDKVersion = Version{2, 0}
|
||||
const sdkMjr, sdkMnr = 2, 0
|
||||
|
||||
func (v Version) String() string {
|
||||
return fmt.Sprintf("v%d.%d", v.Major, v.Minor)
|
||||
// NewVersionFromV2 wraps v2 Version message to Version.
|
||||
func NewVersionFromV2(v *refs.Version) *Version {
|
||||
return (*Version)(v)
|
||||
}
|
||||
|
||||
func (v Version) ToV2Version() *refs.Version {
|
||||
result := new(refs.Version)
|
||||
result.SetMajor(v.Major)
|
||||
result.SetMinor(v.Minor)
|
||||
|
||||
return result
|
||||
// NewVersion creates and initializes blank Version.
|
||||
//
|
||||
// Works similar as NewVersionFromV2(new(Version)).
|
||||
func NewVersion() *Version {
|
||||
return NewVersionFromV2(new(refs.Version))
|
||||
}
|
||||
|
||||
// SDKVersion returns Version instance that
|
||||
// initialized to current SDK revision number.
|
||||
func SDKVersion() *Version {
|
||||
v := NewVersion()
|
||||
v.SetMajor(sdkMjr)
|
||||
v.SetMinor(sdkMnr)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// GetMajor returns major number of the revision.
|
||||
func (v *Version) GetMajor() uint32 {
|
||||
return (*refs.Version)(v).
|
||||
GetMajor()
|
||||
}
|
||||
|
||||
// SetMajor sets major number of the revision.
|
||||
func (v *Version) SetMajor(val uint32) {
|
||||
(*refs.Version)(v).
|
||||
SetMajor(val)
|
||||
}
|
||||
|
||||
// GetMinor returns minor number of the revision.
|
||||
func (v *Version) GetMinor() uint32 {
|
||||
return (*refs.Version)(v).
|
||||
GetMinor()
|
||||
}
|
||||
|
||||
// SetMinor sets minor number of the revision.
|
||||
func (v *Version) SetMinor(val uint32) {
|
||||
(*refs.Version)(v).
|
||||
SetMinor(val)
|
||||
}
|
||||
|
||||
// ToV2 converts Version to v2 Version message.
|
||||
func (v *Version) ToV2() *refs.Version {
|
||||
return (*refs.Version)(v)
|
||||
}
|
||||
|
||||
func (v *Version) String() string {
|
||||
return fmt.Sprintf("v%d.%d", v.GetMajor(), v.GetMinor())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue