Skip to content

proposal: cmd/go: add -doctool flag to specify alternative doc servers or pkgsite versions #79870

Description

@hyangah

Proposal Details

Currently, go doc -http serves local HTML documentation using a fixed, hardcoded version of pkgsite
(golang.org/x/pkgsite/cmd/internal/doc). This proposal adds a -doctool flag to go doc allowing users to specify a custom local documentation server binary or dynamically fetch a different pkgsite version.

go doc -http -doctool <spec> ...

Background

When previewing docs with go doc -http, developers and tooling authors often need to:

  1. Test against newer or older versions of pkgsite (e.g., @latest or @v1.2.3).
  2. Serve docs using the local build of pkgsite (for testing or bug fix) or company-internal documentation rendering servers.

Other go commands already support tool-override flags using a pattern, such as go vet -vettool=prog and go fix -fixtool=prog.

Spec

This flag is used only with -http. The flag accepts two types of arguments:

  1. Alternative version or package (@version or <modulepath>@version):
    Shorthands like @latest, v1.2.3, latest, or explicit module paths (e.g., example.com/mypkgsite@v1.0.0). go doc dynamically builds and runs the specified package.

  2. Local binary:
    A local file path or binary name (e.g., -doctool=./mydoc or -doctool=$(which customdoc)). Following the exact same logic as -vettool and -fixtool, the path is resolved using filepath.Abs before any -C directory changes and validated prior to execution.

Compatibility

This change is fully backwards compatible. If -doctool is omitted, go doc -http continues using the default built-in pkgsite version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions