Skip to content
Latchkey

go doc and pkgsite: Read and Serve Go Docs

go doc prints a package or symbol's documentation to the terminal, while pkgsite serves the same docs as the HTML site that powers pkg.go.dev.

Go documentation comes from ordinary comments above declarations. go doc is built into the toolchain for quick lookups; the standalone pkgsite tool renders the full browsable site the old godoc served.

What it does

go doc reads doc comments from the module and prints them as text, optionally for a single symbol. pkgsite (installed separately) runs an HTTP server that renders package documentation as HTML, replacing the deprecated godoc web server.

Common usage

Terminal
go doc net/http
go doc net/http.Client.Do
# serve a browsable docs site for the current module
go install golang.org/x/pkgsite/cmd/pkgsite@latest
pkgsite -http=:8080 .

Options

Command / flagWhat it does
go doc <pkg>Print a package's documentation
go doc <pkg>.<Symbol>Print docs for one symbol
go doc -all <pkg>Print all exported docs, not just the summary
go doc -src <sym>Show the source alongside the docs
pkgsite -http=:PORTServe the HTML docs site on a port
pkgsite <dir>Serve docs for a specific module path

In CI

The legacy godoc binary is deprecated; use pkgsite for a self-hosted site and go doc for scripted checks. pkgsite serves and does not exit, so do not block a job on it. To gate documentation quality, run go vet and lint for missing comments rather than parsing doc output.

Common errors in CI

go doc: no such package or cannot find module providing package means you are outside the module or the import path is wrong. go: cannot find main module; see 'go help modules' means there is no go.mod in scope. For pkgsite, command not found means it was never go installed on the runner.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →