How to use "go/build".ImportDir to get Package struct?

69 views
Skip to first unread message

Hein Meling

unread,
Sep 17, 2020, 7:28:55 AM9/17/20
to golang-nuts
Hi all,

I'm trying to get info about the package, but the code below returns an empty build.Package struct... Anyone know how to use this API to get a populated Package struct?

p, err := build.ImportDir("../paging", build.FindOnly)
if err != nil {
  t.Error(err)
}
fmt.Println(p)

Thanks,
:) Hein

Paul Jolly

unread,
Sep 17, 2020, 7:36:56 AM9/17/20
to Hein Meling, golang-nuts
Hi,

You want to be using https://pkg.go.dev/golang.org/x/tools/go/packages

The docs include an example of how to do this.

Thanks,


Paul
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/eae52a72-8e4a-40b2-aa64-f83a5024328fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages