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")
}
fmt.Println("Dependencies:")
for _, dep := range buildInfo.Deps {
  fmt.Printf("  %s %s\n", dep.Path, dep.Version)
}

This is not my code, I found it on StackOverflow: https://stackoverflow.com/a/59276408/12550134

Thanks to Mark A for sharing it.

Comment

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