github.com/gsquire/gb@v0.4.4-0.20161112235727-3982dc872064/resolver.go (about) 1 package gb 2 3 import ( 4 "os" 5 6 "github.com/constabulary/gb/internal/importer" 7 "github.com/pkg/errors" 8 ) 9 10 type nullImporter struct{} 11 12 func (i *nullImporter) Import(path string) (*importer.Package, error) { 13 return nil, errors.Errorf("import %q not found") 14 } 15 16 type srcImporter struct { 17 Importer 18 im importer.Importer 19 } 20 21 func (i *srcImporter) Import(path string) (*importer.Package, error) { 22 pkg, err := i.im.Import(path) 23 if err == nil { 24 return pkg, nil 25 } 26 27 // gb expects, when there is a failure to resolve packages that 28 // live in $PROJECT/src that the importer for that directory 29 // will report them. 30 31 pkg, err2 := i.Importer.Import(path) 32 if err2 == nil { 33 return pkg, nil 34 } 35 return nil, err 36 } 37 38 type _importer struct { 39 Importer 40 im importer.Importer 41 } 42 43 func (i *_importer) Import(path string) (*importer.Package, error) { 44 pkg, err := i.im.Import(path) 45 if err != nil { 46 return i.Importer.Import(path) 47 } 48 return pkg, nil 49 } 50 51 type fixupImporter struct { 52 Importer 53 } 54 55 func (i *fixupImporter) Import(path string) (*importer.Package, error) { 56 pkg, err := i.Importer.Import(path) 57 switch err.(type) { 58 case *os.PathError: 59 return nil, errors.Wrapf(err, "import %q: not found", path) 60 default: 61 return pkg, err 62 } 63 }