-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec25a49
commit 2afe9e4
Showing
4 changed files
with
78 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,33 @@ | ||
package version | ||
|
||
import ( | ||
"runtime" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
const Version = "5.3.0" | ||
|
||
var vsnOnce sync.Once | ||
var vsn string | ||
|
||
func isDevel(vsn string) bool { | ||
return strings.Count(vsn, " ") > 2 || strings.HasPrefix(vsn, "devel") | ||
} | ||
|
||
// GoVersion reports the Go version, in a format that is consumable by metrics | ||
// tools. | ||
func GoVersion() string { | ||
vsnOnce.Do(func() { | ||
vsn = strings.TrimPrefix(runtime.Version(), "go") | ||
}) | ||
return vsn | ||
} | ||
|
||
// DevelGoVersion reports whether the version of Go that compiled or ran this | ||
// library is a development ("tip") version. This is useful to distinguish | ||
// because tip versions include a commit SHA and change frequently, so are less | ||
// useful for metric reporting. | ||
func DevelGoVersion() bool { | ||
return isDevel(GoVersion()) | ||
} |
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,12 @@ | ||
package version | ||
|
||
import "testing" | ||
|
||
func TestDevel(t *testing.T) { | ||
if isDevel("1.23.4") { | ||
t.Errorf("expected 1.23.4 to return false; got true") | ||
} | ||
if !isDevel("devel go1.24-d1d9312950 Wed Jan 1 21:18:59 2025 -0800 darwin/arm64") { | ||
t.Errorf("expected tip version to return true; got false") | ||
} | ||
} |