Skip to content
Latchkey

go doc: Usage, Options & Common CI Errors

Read Go documentation without leaving the terminal.

go doc prints the documentation for a package or a specific symbol straight to stdout. Unlike godoc (a separate web server tool), go doc is built into the toolchain and is read-only.

What it does

Resolves a package path (or symbol within one) and prints its doc comments and signatures. -all dumps the entire package; -src shows the source of a symbol.

Common usage

Terminal
go doc fmt                        # package summary
go doc fmt.Println                # one symbol
go doc -all net/http              # full package docs
go doc -src strings.TrimSpace     # show the source

Common CI error: package not found

go doc example.com/pkg fails with "doc: no such package" when the module is not in the build list or the path is mistyped. Fix: run inside the module after go mod download so the dependency is resolvable, and use the exact import path (check it with go list -m all).

Options

FlagEffect
-allPrint all package docs
-srcShow the source code
-uInclude unexported symbols

Related guides

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