GoPLS Viewer

Home|gopls/go/packages/example_test.go
1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package packages_test
6
7import (
8    "flag"
9    "fmt"
10    "os"
11
12    "golang.org/x/tools/go/packages"
13)
14
15// Example demonstrates how to load the packages specified on the
16// command line from source syntax.
17func Example() {
18    flag.Parse()
19
20    // Many tools pass their command-line arguments (after any flags)
21    // uninterpreted to packages.Load so that it can interpret them
22    // according to the conventions of the underlying build system.
23    cfg := &packages.Config{Modepackages.NeedFiles | packages.NeedSyntax}
24    pkgserr := packages.Load(cfgflag.Args()...)
25    if err != nil {
26        fmt.Fprintf(os.Stderr"load: %v\n"err)
27        os.Exit(1)
28    }
29    if packages.PrintErrors(pkgs) > 0 {
30        os.Exit(1)
31    }
32
33    // Print the names of the source files
34    // for each package listed on the command line.
35    for _pkg := range pkgs {
36        fmt.Println(pkg.IDpkg.GoFiles)
37    }
38}
39
MembersX
flag
fmt
Example
Example.err
os
packages
Example.cfg
Example.pkgs
Example.RangeStmt_926.pkg
Members
X