I’m trying to use “go/import” to find all the types in a package without much success.
When I use the example code from a similar StackOverflow answer it all works fine and the output makes sense.
package main
import (
"fmt"
"go/importer"
)
func main() {
pkg, err := importer.Default().Import("time")
if err != nil {
fmt.Printf("error: %s\n", err.Error())
return
}
for _, declName := range pkg.Scope().Names() {
fmt.Println(declName)
}
}
But when I change the package time
to .
or the import path of one of my packages, I get an error message that reads:
error: can't find import: /Users/mgilbir/Projects/go/src/bitbucket.org/mgilbir/importest
To be honest I’m at a loss of ideas of where to look next. What am I missing? How can I get this code working for the current package?