Print runtime dependencies in Golang

Getting a list of dependencies in Go is easy, but third-party libs have their dependencies, and it might not be obvious which ones get into the binary.

Go does provide a way by using runtmime.debug.ReadBuildInfo().Deps. Just add this to your application and it will print all dependencies:

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
  panic("Can't read BuildInfo")
for _, dep := range buildInfo.Deps {
  fmt.Printf("  %s %s\n", dep.Path, dep.Version)

This is not my code, I found it on StackOverflow:

Thanks to Mark A for sharing it.


Your email address will not be published. Required fields are marked *