Go to file
2025-08-17 15:59:01 +02:00
cmd/docreflect init repo 2025-08-08 21:44:31 +02:00
generate testing generate 2025-08-17 15:59:01 +02:00
internal/tests/src testing generate 2025-08-17 15:59:01 +02:00
.gitignore testing generate 2025-08-17 15:59:01 +02:00
docs_test.go fix struct field docs 2025-08-09 20:39:45 +02:00
docs.go fix struct field docs 2025-08-09 20:39:45 +02:00
go.mod init repo 2025-08-08 21:44:31 +02:00
go.sum init repo 2025-08-08 21:44:31 +02:00
Makefile testing generate 2025-08-17 15:59:01 +02:00
readme.md update docs 2025-08-08 21:47:23 +02:00

Docreflect

Library and command to help accessing go doc comments during runtime.

Go doc comments are not accessible during runtime vi reflection. To make them avaiable during runtime, we need to capture them during build time. The docreflect command, or the docreflect/generate library package, fetches the go doc comments of the specified declarations, and generates Go code that registers the docs for every declaration. Code that includes the generated initialization code, will have the docs accessible via the top level docreflect package methods.

Declarations:

  • the declarations must be absolute Go paths
  • when passing in the import path of a package, all the top level symbols of the package, plus the struct fields and methods of the top level types will be included
  • the package documentation can be fetched using docreflect.Docs("absolute/import/path/of/package")
  • when passing in the import path of only the selected symbols, the rest of the package level symbols will be ignroed

Library documentation: https://godocs.io/code.squareroundforest.org/arpio/docreflect

To insall the docreflect command, run:

make install

Usage of the docreflect command:

docreflect generate --package-name mypackage coderepos.org/jdoe/mypackage > docreflect.go