Google doesn’t have much on this topic, so here is what I found.
- You can’t use
reflect
to inspect a package at runtime.
- You can use
go/parser
to inspect the package if you have access to the source code
I needed to inspect a package to facilitate generating code at compile time. So
the go/parser
route worked fine for me.
The following code prints out the types
and consts
and functions
found in the files of the ./events_pb
package.
Output looks like this