diff options
| author | Julie Qiu <julie@golang.org> | 2019-10-07 17:24:56 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:44 -0400 |
| commit | 55f326baf661f3dccf9b457236b4a239dffba612 (patch) | |
| tree | 6a26d7b5ab085bad59323440e47de41b7d6b2aeb /internal/stdlib/stdlib.go | |
| parent | 55d00fdccee8028e2e4fdf383e7b9a2c9e92a857 (diff) | |
| download | go-x-pkgsite-55f326baf661f3dccf9b457236b4a239dffba612.tar.xz | |
internal/stdlib: export VersionForTag
VersionForTag will be used in internal/frontend in the next
set of CLs for the new URL design.
Updates b/140191811
Change-Id: I85c11ac0d6e8c5e8c1040f2dbdc6a385a3e4ee09
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/567617
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/stdlib/stdlib.go')
| -rw-r--r-- | internal/stdlib/stdlib.go | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go index c28f423d..f73561ac 100644 --- a/internal/stdlib/stdlib.go +++ b/internal/stdlib/stdlib.go @@ -37,6 +37,39 @@ import ( // ModulePath is the name of the module for the standard library. const ModulePath = "std" +var ( + // Regexp for matching go tags. The groups are: + // 1 the major.minor version + // 2 the patch version, or empty if none + // 3 the entire prerelease, if present + // 4 the prerelease type ("beta" or "rc") + // 5 the prerelease number + tagRegexp = regexp.MustCompile(`^go(\d+\.\d+)(\.\d+|)((beta|rc)(\d+))?$`) +) + +// VersionForTag returns the semantic version for the Go tag, or "" if +// tag doesn't correspond to a Go release or beta tag. +// Examples: +// "go1.2" => "v1.2.0" +// "go1.13beta1" => "v1.13.0-beta.1" +// "go1.9rc2" => "v1.9.0-rc.2" +func VersionForTag(tag string) string { + m := tagRegexp.FindStringSubmatch(tag) + if m == nil { + return "" + } + version := "v" + m[1] + if m[2] != "" { + version += m[2] + } else { + version += ".0" + } + if m[3] != "" { + version += "-" + m[4] + "." + m[5] + } + return version +} + // TagForVersion returns the Go standard library repository tag corresponding // to semver. The Go tags differ from standard semantic versions in a few ways, // such as beginning with "go" instead of "v". @@ -169,7 +202,7 @@ func Versions() (_ []string, err error) { if !name.IsTag() { continue } - v := versionForTag(name.Short()) + v := VersionForTag(name.Short()) if v != "" { versions = append(versions, v) } @@ -177,39 +210,6 @@ func Versions() (_ []string, err error) { return versions, nil } -var ( - // Regexp for matching go tags. The groups are: - // 1 the major.minor nversion - // 2 the patch version, or empty if none - // 3 the entire prerelease, if present - // 4 the prerelease type ("beta" or "rc") - // 5 the prerelease number - tagRegexp = regexp.MustCompile(`^go(\d+\.\d+)(\.\d+|)((beta|rc)(\d+))?$`) -) - -// versionForTag returns the semantic version for the Go tag, or "" if -// tag doesn't correspond to a Go release or beta tag. -// Examples: -// "go1.2" => "v1.2.0" -// "go1.13beta1" => "v1.13.0-beta.1" -// "go1.9rc2" => "v1.9.0-rc.2" -func versionForTag(tag string) string { - m := tagRegexp.FindStringSubmatch(tag) - if m == nil { - return "" - } - version := "v" + m[1] - if m[2] != "" { - version += m[2] - } else { - version += ".0" - } - if m[3] != "" { - version += "-" + m[4] + "." + m[5] - } - return version -} - // Directory returns the directory of the standard library relative to the repo root. func Directory(version string) string { // For versions older than v1.4.0-beta.1, the stdlib is in src/pkg. |
