Go documentation tools describe the code itself: doc comments, go doc, runnable examples and the pages on pkg.go.dev. Collaboration tools coordinate the people who write it: version control, code review, issue tracking and CI. Documentation answers "what does this package do and how do I use it?", while collaboration tooling answers "who is changing what, and is it safe to merge?".
The two overlap in practice, because a pull request that changes a public API should also change its doc comment, and CI can check both. This article separates the two groups, shows how each works in a current Go toolchain, and explains how teams combine them.
Go treats documentation as part of the source. You write a comment directly above a package, function, type, constant or variable, and the toolchain turns it into reference pages. Nothing else needs to be maintained, so the documentation cannot drift far from the code it sits next to.
| Tool | What it does |
|---|---|
| Doc comments | Plain comments above a declaration, starting with the name of the thing they describe |
go doc | Prints documentation for a package, symbol or method in the terminal |
| pkg.go.dev | Public documentation site that renders doc comments for every module the Go proxy has seen |
pkgsite | The open source server behind pkg.go.dev, which you can run locally or inside a company |
| Example functions | ExampleXxx functions in _test.go files that appear in the docs and are verified by go test |
gofmt | Reformats doc comments to the standard layout, including lists, headings and code blocks |
The old standalone godoc command is no longer part of the Go distribution, and go doc plus pkg.go.dev replaced it for almost everyone. If you need a private documentation site, run pkgsite instead of godoc.
A doc comment is a normal comment placed immediately before the declaration, with no blank line between them. By convention it is a full sentence that starts with the name of the thing being documented.
Run go doc inventory.Store.Reserve in the module and the terminal prints the signature and the comment. The same text becomes the page on pkg.go.dev once the module is published.
Since Go 1.19 doc comments support headings, lists and links in a small, well-defined syntax, and gofmt rewrites them into the canonical form. Indented lines become code blocks, and a link such as [Store] refers to another symbol in the same package. If a function is deprecated, start a paragraph with Deprecated: and the tooling will flag it in editors and on pkg.go.dev.
Example functions are the strongest documentation feature in Go because the compiler and test runner check them. A function named ExampleStore_Reserve in inventory_test.go is attached to the Reserve method in the generated docs. If it has an // Output: comment, go test runs it and fails when the real output differs.
Because the output is verified on every test run, an example that goes stale breaks the build instead of silently misleading readers. Longer prose such as a README.md, architecture notes or a doc.go file complements the generated reference and covers setup, design decisions and contribution rules.
Collaboration tools do not read your doc comments. They manage who edits the code, how changes are reviewed and how quickly the team learns that something broke. Go itself ships very little here, because the language relies on common tools that work for any stack.
v1.4.2, so a release is a Git tag.CODEOWNERS file that routes changes to the right reviewers.gopls, gofmt and golangci-lint give every developer the same formatting and static checks regardless of editor.A minimal GitHub Actions workflow that gives the whole team the same checks looks like this:
Setting go-version-file: go.mod keeps CI on the same Go version the module declares, so local and remote builds agree.
| Question | Documentation tools | Collaboration tools |
|---|---|---|
| Primary audience | Users and future maintainers of the code | The team working on the code today |
| Source of truth | Comments, examples and README.md in the repository | Repository history, reviews, issues and CI results |
| Goal | Explain behaviour and usage | Coordinate changes and catch regressions |
| Typical output | Package pages, go doc output, tested examples | Merged pull requests, release tags, build status |
| Failure when neglected | Readers guess at behaviour or misuse the API | Conflicting changes, broken main branch, unclear ownership |
The tools work best when collaboration rules enforce documentation quality. A common setup has three parts. The pull request template asks whether public API changes include updated doc comments. CI runs go vet, go test (which executes examples) and a linter that flags exported symbols without comments, such as the revive or staticcheck rules for doc comments. A tag push on main publishes a new module version, and pkg.go.dev picks it up automatically once someone requests it or a user fetches it through the Go proxy.
Reviews then double as documentation reviews: reviewers read the doc comment next to the code and ask whether it still tells the truth.
No. The standalone godoc command is no longer shipped with Go. Use go doc in the terminal and pkg.go.dev for the web, or run pkgsite for a private site.
No. Push a tagged version of your module to a public repository and pkg.go.dev renders its doc comments. Private modules need a self-hosted pkgsite.
It can check parts of it. go test verifies example output, go vet catches malformed constructs, and linters can require comments on exported names. Whether prose is still accurate is a review task.
None is required. Go works with any Git host and any CI system, and modules only need version tags in the repository.
Go documentation tools (doc comments, go doc, tested examples, pkg.go.dev and pkgsite) explain what the code does and keep that explanation next to the source. Collaboration tools (Git hosting, code review, issue trackers, CI and shared linters) coordinate the people changing it. Use doc comments and examples for the reference, and use reviews and CI to make sure they stay accurate.