Version returns the semantic version of the build. Use golang.org/x/mod/semver to compare versions.
()
| 47 | // Version returns the semantic version of the build. |
| 48 | // Use golang.org/x/mod/semver to compare versions. |
| 49 | func Version() string { |
| 50 | readVersion.Do(func() { |
| 51 | revision, valid := Revision() |
| 52 | if valid { |
| 53 | revision = "+" + revision[:7] |
| 54 | } |
| 55 | if tag == "" { |
| 56 | // This occurs when the tag hasn't been injected, |
| 57 | // like when using "go run". |
| 58 | // <version>-<pre-release>+<revision> |
| 59 | version = fmt.Sprintf("%s-%s%s", noVersion, develPreRelease, revision) |
| 60 | return |
| 61 | } |
| 62 | version = "v" + tag |
| 63 | // The tag must be prefixed with "v" otherwise the |
| 64 | // semver library will return an empty string. |
| 65 | if semver.Build(version) == "" { |
| 66 | version += revision |
| 67 | } |
| 68 | }) |
| 69 | return version |
| 70 | } |
| 71 | |
| 72 | // VersionsMatch compares the two versions. It assumes the versions match if |
| 73 | // the major and the minor versions are equivalent. Patch versions are |