docreflect

package module
v0.0.0-...-40bd187 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 5 Imported by: 1

README

Docreflect

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

Go doc comments are not accessible during runtime via 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

Gotchas:

  • type aliases and type definitions based on named types are not resolved
  • package imports are not resolved, necessary packages need to be included in the generate arguments

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 coderepos.org/jdoe/otherpackage > docreflect.go

Made in Berlin, DE

Documentation

Overview

Package docreflect returns the Go documentation for packages, types and functions.

The Go documentation of packages is not available during runtime by default, so in order to use docreflect, the documentation for the selected packages and symbols needs to be generated during build time. To generate the documentation, see the docreflect/generate package or the docreflect generate command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Docs

func Docs(gopath string) string

Docs returns the documentation for a package or a symbol in a package identified by its full go path.

func Field

func Field(t reflect.Type, fieldPath ...string) string

Field returns the docuemntation for a struct field.

func Function

func Function(v reflect.Value) string

Function returns the documentation for a package level function.

func FunctionParams

func FunctionParams(v reflect.Value) []string

FunctionParams returns the list of the parameter names of a package level function.

func Method

func Method(t reflect.Type, name string) string

Method returns the documentation for a type method.

func MethodParams

func MethodParams(t reflect.Type, name string) []string

MethodParams returns the list of the parameter names of a type method.

func Register

func Register(gopath, docs string)

Register is used by the code generated by the docreflect/generate package or the docreflect generate command to register the selected documentation during startup. Register is not meant to be used directly by importing packages.

func Type

func Type(t reflect.Type) string

Type returns the docuemntation for a package level type.

Types

This section is empty.

Directories

Path Synopsis
cmd
docreflect command
Package generate provides a generator to generate go code from go docs that registers doc entries for use with the docreflect package.
Package generate provides a generator to generate go code from go docs that registers doc entries for use with the docreflect package.
internal
tests/src/testpackage
Package testpackage is a test package
Package testpackage is a test package

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL