PackageDoc generates Markdown documentation for the package in the given directory. importPath is the full Go import path of that package (e.g. "tailscale.com/tsnet"); it's used to render [Symbol] doc links to the right pkg.go.dev URL. If importPath is empty, build.ImportDir's guess is used (typical
(dir, importPath string)
| 210 | // right pkg.go.dev URL. If importPath is empty, build.ImportDir's guess |
| 211 | // is used (typically "." for module-based repos). |
| 212 | func PackageDoc(dir, importPath string) ([]byte, error) { |
| 213 | var buf bytes.Buffer |
| 214 | var writer io.Writer = &buf |
| 215 | |
| 216 | buildPackage, err := build.ImportDir(dir, build.ImportComment) |
| 217 | if err != nil { |
| 218 | var noGoError *build.NoGoError |
| 219 | if errors.As(err, &noGoError) { |
| 220 | return nil, nil |
| 221 | } |
| 222 | return nil, err |
| 223 | } |
| 224 | if importPath != "" { |
| 225 | buildPackage.ImportPath = importPath |
| 226 | } |
| 227 | userPath := dir |
| 228 | |
| 229 | pkg := parsePackage(writer, buildPackage, userPath) |
| 230 | pkg.packageDoc() |
| 231 | pkg.flush() |
| 232 | |
| 233 | return buf.Bytes(), nil |
| 234 | } |
no test coverage detected
searching dependent graphs…