internal/frontend: remove /mod references
All requests to /mod/<path> are now redirected to /<path>, so remaining
references are removed.
Change-Id: I1107b822f6b57774c717e9e8e9677ed98855ef98
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/277672
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/frontend/details.go b/internal/frontend/details.go
index f6b5b2e..7d314fc 100644
--- a/internal/frontend/details.go
+++ b/internal/frontend/details.go
@@ -18,7 +18,7 @@
)
// serveDetails handles requests for package/directory/module details pages. It
-// expects paths of the form "[/mod]/<module-path>[@<version>?tab=<tab>]".
+// expects paths of the form "/<module-path>[@<version>?tab=<tab>]".
// stdlib module pages are handled at "/std", and requests to "/mod/std" will
// be redirected to that path.
func (s *Server) serveDetails(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error) {
diff --git a/internal/frontend/fetch.go b/internal/frontend/fetch.go
index eecb73a..c39c849 100644
--- a/internal/frontend/fetch.go
+++ b/internal/frontend/fetch.go
@@ -253,7 +253,7 @@
if moduleMatchingPathPrefix != "" {
// TODO(https://golang.org/issue/40306): Make the link clickable.
return http.StatusNotFound,
- fmt.Sprintf("Package “%s” could not be found, but you can view module “%s” at https://pkg.go.dev/mod/%s.",
+ fmt.Sprintf("Package “%s” could not be found, but you can view module “%s” at https://pkg.go.dev/%s.",
displayPath(fullPath, requestedVersion),
displayPath(moduleMatchingPathPrefix, requestedVersion),
displayPath(moduleMatchingPathPrefix, requestedVersion),
diff --git a/internal/frontend/search.go b/internal/frontend/search.go
index 8a744b7..7a3294a 100644
--- a/internal/frontend/search.go
+++ b/internal/frontend/search.go
@@ -194,17 +194,14 @@
if !strings.Contains(requestedPath, "/") {
return ""
}
- um, err := ds.GetUnitMeta(ctx, requestedPath, internal.UnknownModulePath, internal.LatestVersion)
+ _, err := ds.GetUnitMeta(ctx, requestedPath, internal.UnknownModulePath, internal.LatestVersion)
if err != nil {
if !errors.Is(err, derrors.NotFound) {
log.Errorf(ctx, "searchRequestRedirectPath(%q): %v", requestedPath, err)
}
return ""
}
- if um.IsPackage() || um.ModulePath != requestedPath {
- return fmt.Sprintf("/%s", requestedPath)
- }
- return fmt.Sprintf("/mod/%s", requestedPath)
+ return fmt.Sprintf("/%s", requestedPath)
}
// searchQuery extracts a search query from the request.
diff --git a/internal/frontend/search_test.go b/internal/frontend/search_test.go
index baeefa7..6375ae0 100644
--- a/internal/frontend/search_test.go
+++ b/internal/frontend/search_test.go
@@ -214,7 +214,7 @@
query string
want string
}{
- {"module", "golang.org/x/tools", "/mod/golang.org/x/tools"},
+ {"module", "golang.org/x/tools", "/golang.org/x/tools"},
{"directory", "golang.org/x/tools/internal", "/golang.org/x/tools/internal"},
{"package", "golang.org/x/tools/internal/lsp", "/golang.org/x/tools/internal/lsp"},
{"stdlib package does not redirect", "errors", ""},
@@ -222,7 +222,7 @@
{"stdlib directory does redirect", "cmd/go/internal", "/cmd/go/internal"},
{"std does not redirect", "std", ""},
{"non-existent path does not redirect", "github.com/non-existent", ""},
- {"trim URL scheme from query", "https://golang.org/x/tools", "/mod/golang.org/x/tools"},
+ {"trim URL scheme from query", "https://golang.org/x/tools", "/golang.org/x/tools"},
} {
t.Run(test.name, func(t *testing.T) {
if got := searchRequestRedirectPath(ctx, testDB, test.query); got != test.want {
diff --git a/internal/frontend/server.go b/internal/frontend/server.go
index 7513ef4..c2151b7 100644
--- a/internal/frontend/server.go
+++ b/internal/frontend/server.go
@@ -191,9 +191,6 @@
if urlPath == "/" {
return defaultTTL
}
- if strings.HasPrefix(urlPath, "/mod") {
- urlPath = strings.TrimPrefix(urlPath, "/mod")
- }
info, err := parseDetailsURLPath(urlPath)
if err != nil {
log.Errorf(ctx, "falling back to default TTL: %v", err)
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index da9899f..e1221db 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -1019,11 +1019,6 @@
{mustRequest("/host.com/module@v1.2.3/suffix?tab=overview", t), longTTL},
{mustRequest("/host.com/module@v1.2.3/suffix?tab=versions", t), defaultTTL},
{mustRequest("/host.com/module@v1.2.3/suffix?tab=importedby", t), defaultTTL},
- {mustRequest("/mod/host.com/module@v1.2.3/suffix", t), longTTL},
- {mustRequest("/mod/host.com/module/suffix", t), shortTTL},
- {mustRequest("/mod/host.com/module@v1.2.3/suffix?tab=overview", t), longTTL},
- {mustRequest("/mod/host.com/module@v1.2.3/suffix?tab=versions", t), defaultTTL},
- {mustRequest("/mod/host.com/module@v1.2.3/suffix?tab=importedby", t), defaultTTL},
{
func() *http.Request {
r := mustRequest("/host.com/module@v1.2.3/suffix?tab=overview", t)