aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2023-03-31 11:14:41 -0400
committerRuss Cox <rsc@golang.org>2023-03-31 16:08:49 +0000
commit0c673f092123d018e4c994ed162a59ef6e09bc37 (patch)
tree9ca7b8e6a3146476e1884fc799a646a8552f0f2c /cmd
parent2bd866e379d1b6add48225350a8f767b7a566505 (diff)
downloadgo-x-website-0c673f092123d018e4c994ed162a59ef6e09bc37.tar.xz
cmd/golangorg: add support for module form of Go distributions
Add https://golang.org/toolchain serving appropriate meta tags with mod redirect to https://go.dev/dl/mod. Add https://go.dev/dl/mod/golang.org/toolchain/@v/ redirecting to files in https://dl.google.com/go/. Add https://go.dev/dl/mod/golang.org/toolchain/@v/list listing stable toolchain versions. For golang/go#57001. Change-Id: Ib3283cab1d8ead0373ca7549f0e17ccba7cfaa22 Reviewed-on: https://go-review.googlesource.com/c/website/+/480840 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/golangorg/server.go29
-rw-r--r--cmd/golangorg/testdata/web.txt23
2 files changed, 50 insertions, 2 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go
index 239831a7..488e8387 100644
--- a/cmd/golangorg/server.go
+++ b/cmd/golangorg/server.go
@@ -222,6 +222,7 @@ func NewHandler(contentDir, goroot string) http.Handler {
// Note: Only golang.org/x/, no go.dev/x/.
mux.Handle("golang.org/x/", http.HandlerFunc(xHandler))
+ mux.Handle("golang.org/toolchain", http.HandlerFunc(toolchainHandler))
redirect.Register(mux)
@@ -573,8 +574,8 @@ func xHandler(w http.ResponseWriter, r *http.Request) {
}
var xTemplate = template.Must(template.New("x").Parse(`<!DOCTYPE html>
-<html>
-<head>
+<html lang="en">
+<title>The Go Programming Language</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="golang.org/x/{{.Proj}} git https://go.googlesource.com/{{.Proj}}">
<meta name="go-source" content="golang.org/x/{{.Proj}} https://github.com/golang/{{.Proj}}/ https://github.com/golang/{{.Proj}}/tree/master{/dir} https://github.com/golang/{{.Proj}}/blob/master{/dir}/{file}#L{line}">
@@ -586,6 +587,30 @@ var xTemplate = template.Must(template.New("x").Parse(`<!DOCTYPE html>
</html>
`))
+func toolchainHandler(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/toolchain" {
+ // Shouldn't happen if handler is registered correctly.
+ http.NotFound(w, r)
+ return
+ }
+ w.Write(toolchainPage)
+}
+
+var toolchainPage = []byte(`<!DOCTYPE html>
+<html lang="en">
+<head>
+<title>The Go Programming Language</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<meta name="go-import" content="golang.org/toolchain mod https://go.dev/dl/mod">
+<meta http-equiv="refresh" content="0; url=https://go.dev/dl/">
+</head>
+<body>
+golang.org/toolchain is the module form of the Go toolchain releases.
+<a href="https://go.dev/dl/">Redirecting to Go toolchain download page...</a>
+</body>
+</html>
+`)
+
var _ fs.ReadDirFS = unionFS{}
// A unionFS is an FS presenting the union of the file systems in the slice.
diff --git a/cmd/golangorg/testdata/web.txt b/cmd/golangorg/testdata/web.txt
index 68bcfbab..bdff81d3 100644
--- a/cmd/golangorg/testdata/web.txt
+++ b/cmd/golangorg/testdata/web.txt
@@ -2,6 +2,11 @@ GET https://golang.org/
code == 301
redirect == https://go.dev/
+GET https://golang.org/toolchain
+code == 200
+body contains <meta name="go-import" content="golang.org/toolchain mod https://go.dev/dl/mod">
+body contains <meta http-equiv="refresh" content="0; url=https://go.dev/dl/">
+
GET http://localhost:6060/
redirect == /go.dev/
@@ -419,6 +424,24 @@ GET https://go.dev/dl/?mode=json
body contains .windows-amd64.msi
body !contains UA-
+GET https://go.dev/dl/go1.10.darwin-amd64.tar.gz
+redirect == https://dl.google.com/go/go1.10.darwin-amd64.tar.gz
+
+GET https://go.dev/dl/mod/golang.org/toolchain/@v/v0.0.1-go1.20.2.darwin-amd64.zip
+redirect == https://dl.google.com/go/v0.0.1-go1.20.2.darwin-amd64.zip
+
+GET https://go.dev/dl/mod/golang.org/toolchain/@v/v0.0.1-go1.20.2.darwin-amd64.mod
+redirect == https://dl.google.com/go/v0.0.1-go1.20.2.darwin-amd64.mod
+
+GET https://go.dev/dl/mod/golang.org/toolchain/@v/v0.0.1-go1.20.2.darwin-amd64.info
+redirect == https://dl.google.com/go/v0.0.1-go1.20.2.darwin-amd64.info
+
+GET https://go.dev/dl/mod/golang.org/toolchain/@v/list
+body ~ (?m)^v0\.0\.1-go1\.\d+\.\d+.darwin-arm64$
+body ~ (?m)^v0\.0\.1-go1\.\d+\.\d+.darwin-amd64$
+body ~ (?m)^v0\.0\.1-go1\.\d+\.\d+.linux-386$
+body ~ (?m)^v0\.0\.1-go1\.\d+\.\d+.windows-amd64$
+
GET https://go.dev/ref
redirect == /doc/#references