8 "golang.org/x/tools/go/packages"
11 // Example demonstrates how to load the packages specified on the
12 // command line from source syntax.
16 // Many tools pass their command-line arguments (after any flags)
17 // uninterpreted to packages.Load so that it can interpret them
18 // according to the conventions of the underlying build system.
19 cfg := &packages.Config{Mode: packages.NeedFiles | packages.NeedSyntax}
20 pkgs, err := packages.Load(cfg, flag.Args()...)
22 fmt.Fprintf(os.Stderr, "load: %v\n", err)
25 if packages.PrintErrors(pkgs) > 0 {
29 // Print the names of the source files
30 // for each package listed on the command line.
31 for _, pkg := range pkgs {
32 fmt.Println(pkg.ID, pkg.GoFiles)