importer.Default not able to find packages in $GOPATH

357 views
Skip to first unread message

Joshua Liebow-Feeser

unread,
Jun 17, 2016, 3:21:55 PM6/17/16
to golang-nuts
Hi All,

I'm trying to use the go/* packages to parse and type check Go source code. I've downloaded github.com/coreos/etcd to test this on, and I'm currently trying it out in the etcdserver subdirectory. When I run 'go build' everything works fine, but when I try to type check, none of the imports are found. For each import, I get an error like:


(my $GOPATH is /home/josh/workspace/go)

I'm using the default importer (importer.Default()), and I compiled my tool with the gc compiler (I tried it for both go1.5 and go1.6).

Is there something obvious that I'm missing here?

Thanks!
Cheers,
Josh

adon...@google.com

unread,
Jun 17, 2016, 5:15:43 PM6/17/16
to golang-nuts
On Friday, 17 June 2016 15:21:55 UTC-4, Joshua Liebow-Feeser wrote:
Hi All,

I'm trying to use the go/* packages to parse and type check Go source code. I've downloaded github.com/coreos/etcd to test this on, and I'm currently trying it out in the etcdserver subdirectory. When I run 'go build' everything works fine, but when I try to type check, none of the imports are found.

Try running 'go install' or 'go build -i' on the packages you want to analyze.

The default importer works great for packages in the standard library, which are always available in compiled form, but poorly for user packages, for which it may have been days or weeks since the most recent install.  Take a look at the golang.org/x/tools/go/loader package, which loads all packages from source.

Also, you may find this tutorial helpful: https://github.com/golang/example/tree/master/gotypes

Joshua Liebow-Feeser

unread,
Jun 17, 2016, 5:23:50 PM6/17/16
to adon...@google.com, golang-nuts
'go install' worked; thanks a ton! I'll also take a look at the other stuff you mentioned because I'm curious about the details.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/kJmbdFqQ0is/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages