Package documentation in Go
A comment directly above the package clause documents the package.
// Package tour models a language's practice tours: an ordered run of
// sets, each holding steps that a player types in turn.
package tour
// Step is one snippet in a tour, with the speed target that earns
// three stars.
type Step struct {
Title string
TargetTPM int
}
// Tour holds the steps of one tour, in play order.
type Tour struct {
Slug string
Steps []Step
}
// Len reports how many steps the tour holds.
func (t Tour) Len() int { return len(t.Steps) }
How it works
- The doc comment starts with the package name.
- Exported identifiers get their own comments, starting with the name.
go docand pkg.go.dev render exactly this.
Keywords and builtins used here
funcintlenreturnstringstructtype
The run, in numbers
- Lines
- 19
- Characters to type
- 470
- Tokens
- 46
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 26 seconds.
Step 1 of 5 in Packages & build, step 21 of 26 in Standard library & project layout.