Guides
Use a module in a subdirectory
Use this guide for a repository whose Go module is not at the root, such as a module in v2.
Give the module directory§
Put a .docgen.yaml at the repository root, so that each run uses the same module:
module: v2The -module flag also works, and overrides the file:
docgen update -module v2The path is relative to the repository root. With it:
pkg=paths are relative to the module, sopkg=machineisv2/machine.docgen:gomodreadsv2/go.mod.- The
tagssetting applies to the code of this module. file=andcmd=stay relative to the repository root, so an excerpt hasfile=v2/machine/machine.goand a program hascmd=v2/examples/hello.
docgen reads one module per run. The import path in each link comes from the go.mod of that module.
For a module in v2, pkg=machine reads v2/machine:
v2/machine/machine.go
const DefaultWait = 250 * time.Milliseconddocs/machines/guide-const.md
Before
The default wait is <!-- docgen:const pkg=machine name=DefaultWait --><!-- /docgen:const -->.
After
The default wait is <!-- docgen:const pkg=machine name=DefaultWait -->`250ms`<!-- /docgen:const -->.
Preview
The default wait is 250ms.
Tools in other modules§
A directory with a go.mod of its own is another module:
pkg=does not match it as a package of the main module.docgen:docreads its package doc whenpkg=is its path from the repository root.docgen:usageruns it from its nearestgo.mod.
<!-- docgen:doc pkg=tools/gen -->
<!-- /docgen:doc -->
<!-- docgen:usage cmd=tools/gen -->
<!-- /docgen:usage -->