Golang go/build.Package.IsCommand() function examples

package go/build

IsCommand reports whether the package is considered a command to be installed (not just a library). Packages named "main" are treated as commands.

Golang go/build.Package.IsCommand() function usage examples

Example 1:

 var pkg *PackageData

 if !pkg.IsCommand() || pkg.UpToDate {
 fmt.Println("Wrong package")
 os.Exit(1)
 }

Example 2:

 pkg, err := buildContext.Import(path, "", mode)
 if pkg.IsCommand() {
 pkg.PkgObj = filepath.Join(pkg.BinDir, filepath.Base(pkg.ImportPath)+".js")
 }

Reference :

http://golang.org/pkg/go/build/#Package.IsCommand

Advertisement