try "go version -m" On Tuesday, November 2, 2021 at 8:18:15 PM UTC+3 Michel Casabianca wrote:
> Hi gophers, > > I would like to know which dependencies are embedded in generated Go > binary, along with their version. I though at first that they were listed > in *go.sum* file, but it seems that this is not the case. > > I found two different ways to do so: > - Running "go version -m my-binary" > - Calling runtime.debug API in my code, as follows: > > func buildInfo() { > 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) > } > } > > func main() { > // print build info if -info passed on command line > if len(os.Args) > 1 && os.Args[1] == "-info" { > buildInfo() > os.Exit(0) > } > ... > } > > These two methods produce the same list. Does anyone confirm that this is > the way to list embedded dependencies in a Go binary? > > Another question related to this one: > > Let's say I use dependencies A and B that both use C in two different > versions. According to my own experience, it seems that Go will embed only > one of these versions, the latest one. Is this correct? > > Best regards > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1e5ea628-3c95-4f66-8501-c4904d589db4n%40googlegroups.com.