godoc: don't clear user-set page mode for package builtin
When rendering the documentation of the fake package builtin,
there are two PageInfoMode flags that always get set,
regardless of what the user has provided via the ?m= query parameter.
They are:
• NoFiltering
• NoTypeAssoc
This is being done to make the documention of this special package more
usable and helpful (see golang/go#6645).
This change modifies the way those flags are set, so that any additional
flags the user may have set are no longer cleared. This makes it possible,
for example, to use ?m=src to view the source, as it is for all other
packages.
Also elaborate more about this behavior in the comments.
Fixes golang/go#30300
Updates golang/go#6645
Change-Id: I77728bd2683191b97d8f58f19092f2833dfc474c
Reviewed-on: https://go-review.googlesource.com/c/162983
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/godoc/server.go b/godoc/server.go
index b03e14a..693599b 100644
--- a/godoc/server.go
+++ b/godoc/server.go
@@ -268,7 +268,10 @@
abspath := pathpkg.Join(h.fsRoot, relpath)
mode := h.p.GetPageInfoMode(r)
if relpath == builtinPkgPath {
- mode = NoFiltering | NoTypeAssoc
+ // The fake built-in package contains unexported identifiers,
+ // but we want to show them. Also, disable type association,
+ // since it's not helpful for this fake package (see issue 6645).
+ mode |= NoFiltering | NoTypeAssoc
}
info := h.GetPageInfo(abspath, relpath, mode, r.FormValue("GOOS"), r.FormValue("GOARCH"))
if info.Err != nil {
@@ -357,7 +360,7 @@
AllMethods // show all embedded methods
ShowSource // show source code, do not extract documentation
FlatDir // show directory in a flat (non-indented) manner
- NoTypeAssoc // don't associate consts, vars, and factory functions with types
+ NoTypeAssoc // don't associate consts, vars, and factory functions with types (not exposed via ?m= query parameter, used for package builtin, see issue 6645)
)
// modeNames defines names for each PageInfoMode flag.