cmd/internal/pkgsite: improve godoc mode search in GOROOT

If a user starts go doc -http inside of GOROOT, we create three module
getters when we only need one: We create a StdlibZip module getter which
we're not going to use because we're using a local GOROOT, we create a
gopackages module getter for the module determined as corresponding to
the current directory, which is a stdlib module, and finally we create
the NewGoPackagesStdlibModuleGetter, which is the main module getter for
the standard library in that case.

The StdlibZip module getter is not used when we're using a local GOROOT,
so don't add it in that case. And if we detect that the module for a
specified directory is std or cmd for the specified local GOROOT, skip
adding it because it will be redundant with the module getter we create
using NewGoPackagesStdlibModuleGetter specifically for the standard
libarry.

Removing the redundant module getter will prevent redundant search
results returned by each of the gopackages module getters corresponding
to the standard library.

While we're here, if there's a VERSION file in GOROOT, set the version
on the module metadata we return for the standard library to the
stdlib.VersionForTag of that version, so we can report the version in
the search results.

Fixes golang/go#74459

Change-Id: If250f715b052f57f8668b02a57b4c96725be515a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/687918
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Auto-Submit: Michael Matloob <matloob@golang.org>
2 files changed
tree: 280b8ce28d5e2b729d1f42b91ceeac46bfadba20
  1. .github/
  2. cmd/
  3. deploy/
  4. devtools/
  5. doc/
  6. internal/
  7. migrations/
  8. static/
  9. tests/
  10. third_party/
  11. .dockerignore
  12. .eslintignore
  13. .eslintrc.yaml
  14. .gitignore
  15. .prettierignore
  16. .prettierrc.yaml
  17. .stylelintignore
  18. .stylelintrc.yaml
  19. all.bash
  20. CONTRIBUTING.md
  21. go.mod
  22. go.sum
  23. jest.config.js
  24. LICENSE
  25. package-lock.json
  26. package.json
  27. PATENTS
  28. README.md
  29. tsconfig.json
README.md

golang.org/x/pkgsite

This repository hosts the source code of the pkg.go.dev website, and pkgsite, a documentation server program.

Go Reference

pkg.go.dev: a site for discovering Go packages

Pkg.go.dev is a website for discovering and evaluating Go packages and modules.

You can check it out at https://pkg.go.dev.

pkgsite: a documentation server

pkgsite program extracts and generates documentation for Go projects.

Example usage:

$ go install golang.org/x/pkgsite/cmd/pkgsite@latest
$ cd myproject
$ pkgsite -open .

For more information, see the pkgsite documentation.

Issues

If you want to report a bug or have a feature suggestion, please first check the known issues to see if your issue is already being discussed. If an issue does not already exist, feel free to file an issue.

For answers to frequently asked questions, see pkg.go.dev/about.

You can also chat with us on the #pkgsite Slack channel on the Gophers Slack.

Contributing

We would love your help!

Our canonical Git repository is located at go.googlesource.com/pkgsite. There is a mirror of the repository at github.com/golang/pkgsite.

To contribute, please read our contributing guide.

License

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Links