]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: fix -http on Windows
authorqmuntal <quimmuntal@gmail.com>
Fri, 27 Jun 2025 10:45:22 +0000 (12:45 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Sun, 29 Jun 2025 14:01:25 +0000 (07:01 -0700)
On Windows, GOMODCACHE almost never starts with a slash, and
"go doc -http" constructs a GOPROXY URL by doing "file://" + GOMODCACHE,
resulting in an invalid file URI.

For example, if GOMODCACHE is "C:\foo", then the file URI should be
"file:///C:/foo", but it becomes "file://C:/foo" instead, where "C:" is
understood as a host name, not a drive letter.

Fixes #74137.

Change-Id: I23e776e0f649a0062e01d1a4a6ea8268ba467331
Reviewed-on: https://go-review.googlesource.com/c/go/+/684575
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/alldocs.go
src/cmd/go/internal/doc/doc.go
src/cmd/internal/doc/main.go

index e8034bf5d17a2e5e5e25003ef64af84564514832..7403b92cd14a3c46771350cd49617b7509cb5213 100644 (file)
 //
 //     go doc
 //             Show documentation for current package.
+//     go doc -http
+//             Serve HTML documentation over HTTP for the current package.
 //     go doc Foo
 //             Show documentation for Foo in the current package.
 //             (Foo starts with a capital letter so it cannot match
 //
 // Flags:
 //
-//     -all
-//             Show all the documentation for the package.
-//     -c
-//             Respect case when matching symbols.
-//     -cmd
-//             Treat a command (package main) like a regular package.
-//             Otherwise package main's exported symbols are hidden
-//             when showing the package's top-level documentation.
-//     -short
-//             One-line representation for each symbol.
-//     -src
-//             Show the full source code for the symbol. This will
-//             display the full Go source of its declaration and
-//             definition, such as a function definition (including
-//             the body), type declaration or enclosing const
-//             block. The output may therefore include unexported
-//             details.
-//     -u
-//             Show documentation for unexported as well as exported
-//             symbols, methods, and fields.
+//             -all
+//                     Show all the documentation for the package.
+//             -c
+//                     Respect case when matching symbols.
+//             -cmd
+//                     Treat a command (package main) like a regular package.
+//                     Otherwise package main's exported symbols are hidden
+//                     when showing the package's top-level documentation.
+//             -http
+//                     Serve HTML docs over HTTP.
+//             -short
+//                     One-line representation for each symbol.
+//             -src
+//                     Show the full source code for the symbol. This will
+//                     display the full Go source of its declaration and
+//                     definition, such as a function definition (including
+//                     the body), type declaration or enclosing const
+//                     block. The output may therefore include unexported
+//                     details.
+//             -u
+//                     Show documentation for unexported as well as exported
+//                     symbols, methods, and fields.
 //
 // # Print Go environment information
 //
index 131da814951d0f7ac7879c3b137b4d8b7c810c54..74c70e2c7a50164cfa2a377dfe4529ccab8ccf9e 100644 (file)
@@ -75,6 +75,8 @@ different cases. If this occurs, documentation for all matches is printed.
 Examples:
        go doc
                Show documentation for current package.
+       go doc -http
+               Serve HTML documentation over HTTP for the current package.
        go doc Foo
                Show documentation for Foo in the current package.
                (Foo starts with a capital letter so it cannot match
@@ -116,6 +118,8 @@ Flags:
                Treat a command (package main) like a regular package.
                Otherwise package main's exported symbols are hidden
                when showing the package's top-level documentation.
+       -http
+               Serve HTML docs over HTTP.
        -short
                One-line representation for each symbol.
        -src
index fe99ee70bd3a48b59db84e26a4e90f4de9fa1abc..c51fbef5172497c6a1bab7b8409bd69aebea9fea 100644 (file)
@@ -227,8 +227,16 @@ func doPkgsite(urlPath string) error {
        fields := strings.Fields(vars)
        if err == nil && len(fields) == 2 {
                goproxy, gomodcache := fields[0], fields[1]
-               goproxy = "file://" + filepath.Join(gomodcache, "cache", "download") + "," + goproxy
-               env = append(env, "GOPROXY="+goproxy)
+               gomodcache = filepath.Join(gomodcache, "cache", "download")
+               // Convert absolute path to file URL. pkgsite will not accept
+               // Windows absolute paths because they look like a host:path remote.
+               // TODO(golang.org/issue/32456): use url.FromFilePath when implemented.
+               if strings.HasPrefix(gomodcache, "/") {
+                       gomodcache = "file://" + gomodcache
+               } else {
+                       gomodcache = "file:///" + filepath.ToSlash(gomodcache)
+               }
+               env = append(env, "GOPROXY="+gomodcache+","+goproxy)
        }
 
        const version = "v0.0.0-20250608123103-82c52f1754cd"