コード例 #1
0
ファイル: importer.go プロジェクト: ernesto-jimenez/gogen
func importOrErr(base types.Importer, pkg string, err error) (*types.Package, error) {
	p, impErr := base.Import(pkg)
	if impErr != nil {
		return nil, err
	}
	return p, nil
}
コード例 #2
0
ファイル: godex.go プロジェクト: ChloeTigre/golang-tools
// tryPrefixes tries to import the package given by (the possibly partial) path using the given importer imp
// by prepending all possible prefixes to path. It returns with the first package that it could import, or
// with an error.
func tryPrefixes(prefixes chan string, path string, imp types.Importer) (pkg *types.Package, err error) {
	for prefix := range prefixes {
		actual := path
		if prefix == "" {
			// don't use filepath.Join as it will sanitize the path and remove
			// a leading dot and then the path is not recognized as a relative
			// package path by the importers anymore
			logf("\ttrying no prefix\n")
		} else {
			actual = filepath.Join(prefix, path)
			logf("\ttrying prefix %q\n", prefix)
		}
		pkg, err = imp.Import(actual)
		if err == nil {
			break
		}
		logf("\t=> importing %q failed: %s\n", actual, err)
	}
	return
}
コード例 #3
0
ファイル: stmt.go プロジェクト: sbinet/go-eval
// srcImporter implements the ast.Importer signature.
func srcImporter(typesImporter types.Importer, path string) (pkg *types.Package, err error) {
	return typesImporter.Import(path)
}