mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
feat(version): add comparison methods
This commit is contained in:
@@ -43,8 +43,8 @@ func init() {
|
||||
|
||||
type Version struct{ Generation, Major, Minor int }
|
||||
|
||||
func Ver(major, minor, patch int) Version {
|
||||
return Version{major, minor, patch}
|
||||
func Ver(gen, major, minor int) Version {
|
||||
return Version{gen, major, minor}
|
||||
}
|
||||
|
||||
func (v Version) String() string {
|
||||
@@ -55,13 +55,38 @@ func (v Version) MarshalText() ([]byte, error) {
|
||||
return []byte(v.String()), nil
|
||||
}
|
||||
|
||||
func (v Version) IsNewerMajorThan(other Version) bool {
|
||||
func (v Version) IsNewerThan(other Version) bool {
|
||||
if v.Generation != other.Generation {
|
||||
return v.Generation > other.Generation
|
||||
}
|
||||
if v.Major != other.Major {
|
||||
return v.Major > other.Major
|
||||
}
|
||||
return v.Minor > other.Minor
|
||||
}
|
||||
|
||||
func (v Version) IsNewerThanMajor(other Version) bool {
|
||||
if v.Generation != other.Generation {
|
||||
return v.Generation > other.Generation
|
||||
}
|
||||
return v.Major > other.Major
|
||||
}
|
||||
|
||||
func (v Version) IsOlderThan(other Version) bool {
|
||||
return !v.IsNewerThan(other)
|
||||
}
|
||||
|
||||
func (v Version) IsOlderThanMajor(other Version) bool {
|
||||
if v.Generation != other.Generation {
|
||||
return v.Generation < other.Generation
|
||||
}
|
||||
return v.Major < other.Major
|
||||
}
|
||||
|
||||
func (v Version) IsOlderMajorThan(other Version) bool {
|
||||
return !v.IsNewerThanMajor(other)
|
||||
}
|
||||
|
||||
func (v Version) IsEqual(other Version) bool {
|
||||
return v.Generation == other.Generation && v.Major == other.Major && v.Minor == other.Minor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user