diff options
| author | Jonathan Amsterdam <jba@google.com> | 2019-11-12 16:56:14 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-03-27 16:46:48 -0400 |
| commit | d0177a7710ff1eaec7307fa79e9a8a3f90a27621 (patch) | |
| tree | ddf9fc8d84bc1efd6b5d1189fc7537caf9e66e67 /internal/stdlib/stdlib.go | |
| parent | 07ca1c634739ea03179accd590e3efa9c23ce10c (diff) | |
| download | go-x-pkgsite-d0177a7710ff1eaec7307fa79e9a8a3f90a27621.tar.xz | |
internal/stdlib: handle go1
Handle the idiosyncratic mapping of go1 to v1.0.0.
The following frontend paths changed behavior:
- std@go1?tab=versions and archive/tar@go1?tab=versions both work now
- std@go1.0 and archive/tar@go1.0 now return 4xx
Fixes b/144364761.
Change-Id: I2345faeedb1e418028422feaf7d9ad0233bc08ff
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/597504
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Diffstat (limited to 'internal/stdlib/stdlib.go')
| -rw-r--r-- | internal/stdlib/stdlib.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go index adf1cf49..3de7dc89 100644 --- a/internal/stdlib/stdlib.go +++ b/internal/stdlib/stdlib.go @@ -50,10 +50,18 @@ var ( // VersionForTag returns the semantic version for the Go tag, or "" if // tag doesn't correspond to a Go release or beta tag. // Examples: +// "go1" => "v1.0.0" // "go1.2" => "v1.2.0" // "go1.13beta1" => "v1.13.0-beta.1" // "go1.9rc2" => "v1.9.0-rc.2" func VersionForTag(tag string) string { + // Special cases for go1. + if tag == "go1" { + return "v1.0.0" + } + if tag == "go1.0" { + return "" + } m := tagRegexp.FindStringSubmatch(tag) if m == nil { return "" @@ -76,6 +84,10 @@ func VersionForTag(tag string) string { func TagForVersion(version string) (_ string, err error) { defer derrors.Wrap(&err, "TagForVersion(%q)", version) + // Special case: v1.0.0 => go1. + if version == "v1.0.0" { + return "go1", nil + } if !semver.IsValid(version) { return "", derrors.FromHTTPStatus(http.StatusBadRequest, "requested version is not a valid semantic version: %q ", version) } @@ -108,12 +120,15 @@ func TagForVersion(version string) (_ string, err error) { // MajorVersionForVersion returns the Go major version for version. // E.g. "v1.13.3" => "go1". func MajorVersionForVersion(version string) (_ string, err error) { - defer derrors.Wrap(&err, "MajorTagForVersion(%q)", version) + defer derrors.Wrap(&err, "MajorVersionForVersion(%q)", version) tag, err := TagForVersion(version) if err != nil { return "", err } + if tag == "go1" { + return tag, nil + } i := strings.IndexRune(tag, '.') if i < 0 { return "", fmt.Errorf("no '.' in go tag %q", tag) |
