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 sourceCommon 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
| Flag | Effect |
|---|---|
| -all | Print all package docs |
| -src | Show the source code |
| -u | Include unexported symbols |
Related guides
go list: Usage, Options & Common CI Errorsgo list reports information about packages and modules. Learn -m, -json, -f templates, and how to enumerate p…
go build: Usage, Options & Common CI Errorsgo build compiles Go packages and binaries. Learn -o, ./..., cross-compiling with GOOS/GOARCH, and how to fix…
cargo doc: Usage, Options & Common CI Errorscargo doc builds your crate documentation with rustdoc. Learn --no-deps, --open, and how to fail CI on broken…