gddo-server: change redirect for github.com/golang/go requests
Requests to github.com/golang/go and github.com/golang/go/src are now
redirected to pkg.go.dev/std.
Requests to github.com/golang/go/src/<path> are redirected to
pkg.go.dev/<path>.
Change-Id: Iaf9f52d17fc19c3e6c325c260de3f070da32a21b
Reviewed-on: https://go-review.googlesource.com/c/gddo/+/279036
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/gddo-server/pkgsite.go b/gddo-server/pkgsite.go
index 3ee9e71..c5e0aa3 100644
--- a/gddo-server/pkgsite.go
+++ b/gddo-server/pkgsite.go
@@ -203,6 +203,8 @@
}
}
+const goGithubRepoURLPath = "/github.com/golang/go"
+
func pkgGoDevURL(godocURL *url.URL) *url.URL {
u := &url.URL{Scheme: "https", Host: pkgGoDevHost}
q := url.Values{"utm_source": []string{"godoc"}}
@@ -213,6 +215,24 @@
return u
}
+ if strings.HasPrefix(godocURL.Path, goGithubRepoURLPath) ||
+ strings.HasPrefix(godocURL.Path, goGithubRepoURLPath+"/src") {
+ u.Path = strings.TrimPrefix(strings.TrimPrefix(godocURL.Path, goGithubRepoURLPath), "/src")
+ if u.Path == "" {
+ u.Path = "/std"
+ }
+ u.RawQuery = q.Encode()
+ return u
+ }
+
+ _, isSVG := godocURL.Query()["status.svg"]
+ _, isPNG := godocURL.Query()["status.png"]
+ if isSVG || isPNG {
+ u.Path = "/badge" + godocURL.Path
+ u.RawQuery = q.Encode()
+ return u
+ }
+
switch godocURL.Path {
case "/-/go":
u.Path = "/std"
diff --git a/gddo-server/pkgsite_test.go b/gddo-server/pkgsite_test.go
index 8515db6..736d178 100644
--- a/gddo-server/pkgsite_test.go
+++ b/gddo-server/pkgsite_test.go
@@ -148,6 +148,18 @@
to: "https://pkg.go.dev/badge/cloud.google.com/go/storage?utm_source=godoc",
},
{
+ from: "https://godoc.org/github.com/golang/go",
+ to: "https://pkg.go.dev/std?utm_source=godoc",
+ },
+ {
+ from: "https://godoc.org/github.com/golang/go/src",
+ to: "https://pkg.go.dev/std?utm_source=godoc",
+ },
+ {
+ from: "https://godoc.org/github.com/golang/go/src/cmd/vet",
+ to: "https://pkg.go.dev/cmd/vet?utm_source=godoc",
+ },
+ {
from: "https://godoc.org/golang.org/x/vgo/vendor/cmd/go/internal/modfile",
to: "https://pkg.go.dev/?utm_source=godoc",
},