summaryrefslogtreecommitdiffhomepage
path: root/website
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2021-01-07 09:53:33 -0500
committerMichael Pratt <mpratt@google.com>2021-01-07 09:53:33 -0500
commita0037b8976d1ea482e1545adfa65403ca43dbb1a (patch)
treeadbbddba7f047a1f493bb1769d8614a24ff0ac51 /website
parent776016ac6412006671a5dbccb5e9af21bf9b01f7 (diff)
website: redirect module to pkg.go.dev
Add redirects from any module package path to its corressponding pkg.go.dev documentation. e.g., gvisor.dev/gvisor/pkg/sentry/kernel -> https://pkg.go.dev/gvisor.dev/gvisor/pkg/sentry/kernel. This is a handy way to get to documentation, also used by other vanity domains, like golang.org/x/tools.
Diffstat (limited to 'website')
-rw-r--r--website/cmd/server/main.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/website/cmd/server/main.go b/website/cmd/server/main.go
index 84a576858..601ccac5e 100644
--- a/website/cmd/server/main.go
+++ b/website/cmd/server/main.go
@@ -171,7 +171,7 @@ func redirectHandler(target string) http.Handler {
})
}
-// redirectRedirects registers redirect http handlers.
+// registerRedirects registers redirect http handlers.
func registerRedirects(mux *http.ServeMux) {
for prefix, baseURL := range prefixHelpers {
p := "/" + prefix + "/"
@@ -180,6 +180,17 @@ func registerRedirects(mux *http.ServeMux) {
for path, redirect := range redirects {
mux.Handle(path, hostRedirectHandler(wrappedHandler(redirectHandler(redirect))))
}
+ registerModuleDocRedirects(http.DefaultServeMux)
+}
+
+// registerModuleDocs registers redirect http handlers to redirect module paths
+// directly to their docs on pkg.go.dev.
+func registerModuleDocRedirects(mux *http.ServeMux) {
+ const prefix = "/gvisor/"
+ mux.Handle(prefix, hostRedirectHandler(wrappedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ pkg := r.URL.Path[len(prefix):]
+ redirectWithQuery(w, r, fmt.Sprintf("https://pkg.go.dev/gvisor.dev/gvisor/%s", pkg))
+ }))))
}
// registerStatic registers static file handlers.