playground: redirect https://play.golang.org/ to https://go.dev/play
The Go web sites are consolidating into go.dev,
including the playground at https://go.dev/play.
Redirect users (but not API requests) to the new URL.
Change-Id: I9bc4338568d1afd5916a84ec4d26cce2133b9ea0
Reviewed-on: https://go-review.googlesource.com/c/playground/+/364816
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/edit.go b/edit.go
index 500d664..9cb49c9 100644
--- a/edit.go
+++ b/edit.go
@@ -78,11 +78,17 @@
return
}
}
+
+ if r.Host == hostname {
+ // The main playground is now on go.dev/play.
+ http.Redirect(w, r, "https://go.dev/play"+r.URL.Path, http.StatusFound)
+ return
+ }
+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
data := &editData{
Snippet: snip,
Share: allowShare(r),
- Analytics: r.Host == hostname,
GoVersion: runtime.Version(),
Gotip: s.gotip,
Examples: s.examples.examples,
diff --git a/server_test.go b/server_test.go
index 1fb178c..fdac9d7 100644
--- a/server_test.go
+++ b/server_test.go
@@ -72,7 +72,7 @@
{"foo.play.golang.org to play.golang.org", http.MethodGet, "https://foo.play.golang.org", http.StatusFound, map[string]string{"Location": "https://play.golang.org"}, nil},
{"Non-existent page", http.MethodGet, "https://play.golang.org/foo", http.StatusNotFound, nil, nil},
{"Unknown snippet", http.MethodGet, "https://play.golang.org/p/foo", http.StatusNotFound, nil, nil},
- {"Existing snippet", http.MethodGet, "https://play.golang.org/p/" + id, http.StatusOK, nil, nil},
+ {"Existing snippet", http.MethodGet, "https://play.golang.org/p/" + id, http.StatusFound, nil, nil},
{"Plaintext snippet", http.MethodGet, "https://play.golang.org/p/" + id + ".go", http.StatusOK, nil, barBody},
{"Download snippet", http.MethodGet, "https://play.golang.org/p/" + id + ".go?download=true", http.StatusOK, map[string]string{"Content-Disposition": fmt.Sprintf(`attachment; filename="%s.go"`, id)}, barBody},
}