Obtaining compiled module information at run time

180 views
Skip to first unread message

Maxim Khitrov

unread,
Jan 20, 2019, 9:51:07 PM1/20/19
to golang-nuts
I was working on a tool that needed to know the file system paths and
version information of some of its dependencies from go.mod for code
generation. I couldn't find any official way of obtaining these
(debug/gosym was close, but didn't work for the current binary on any
OS), so I wrote this package:

https://github.com/mxk/go-gomod

It's basically a hack that looks through all file name strings used
for stack traces in the current binary, identifies those containing
"@v", and extracts root directory and version information from there.

This got me thinking whether there should be a more general (and
unsafe-free) way of obtaining module information at run time. 'go
list' command defines a Module struct containing pretty much all
information one might want. Would it make sense to compile this
metadata into the binary (if not already done) and expose it via the
runtime package?

-Max

roger peppe

unread,
Jan 21, 2019, 11:44:22 AM1/21/19
to Maxim Khitrov, golang-nuts
Perhaps you were looking for this, which will be available in the upcoming
go1.12 release?


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maxim Khitrov

unread,
Jan 21, 2019, 12:16:17 PM1/21/19
to roger peppe, golang-nuts
Ha! Yes, that looks exactly like what I needed. Thanks for the tip!

-Max
Reply all
Reply to author
Forward
0 new messages