-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Masterminds/semver package to compare versions
- Loading branch information
1 parent
278d5ad
commit 6aadc93
Showing
6 changed files
with
124 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package version | ||
|
||
import "github.com/Masterminds/semver/v3" | ||
|
||
// Compare parses and compares two semantic version numbers. | ||
// It returns -1, 0 or 1, representing whether v1 is less than, equal to or greater than v2. | ||
func Compare(v1, v2 string) (int, error) { | ||
if v1 == v2 { | ||
return 0, nil | ||
} | ||
version1, err := semver.NewVersion(v1) | ||
if err != nil { | ||
return 0, err | ||
} | ||
version2, err := semver.NewVersion(v2) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return version1.Compare(version2), nil | ||
} | ||
|
||
// Validate tests if a version number is valid. | ||
func Validate(v string) bool { | ||
_, err := semver.NewVersion(v) | ||
return err == nil | ||
} |
Oops, something went wrong.