Standard library / go/build
go/build.MultiplePackageError
Represents a directory containing inconsistent package names. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type MultiplePackageError struct { Dir string Packages []string Files []string}Working Example
Example Snippetgo
package main
import ( "errors" "fmt" "go/build" "os" "path/filepath")
func check(e error) { if e != nil { panic(e) }}
func main() { d, e := os.MkdirTemp("", "build-error-") check(e) defer os.RemoveAll(d) check(os.WriteFile(filepath.Join(d, "a.go"), []byte("package a"), 0600)) check(os.WriteFile(filepath.Join(d, "b.go"), []byte("package b"), 0600)) _, e = build.ImportDir(d, 0) var x *build.MultiplePackageError ok := errors.As(e, &x) fmt.Println(ok)}