-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.go
More file actions
48 lines (38 loc) · 815 Bytes
/
import.go
File metadata and controls
48 lines (38 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package play
import (
"fmt"
"go/types"
)
func Importer(config *Config) types.Importer {
return &defaultImporter{
imports: make(map[string]*types.Package),
config: config,
}
}
type defaultImporter struct {
imports map[string]*types.Package
config *Config
}
func (im *defaultImporter) Import(path string) (*types.Package, error) {
if path == "unsafe" {
return types.Unsafe, nil
}
pkg := im.imports[path]
if pkg != nil {
return pkg, nil
}
pkg, err := ImportFromExportData(im.config, path)
if pkg != nil {
im.imports[path] = pkg
return pkg, nil
}
pkg, err = ImportFromVendor(im, im.config, path)
if err != nil {
return nil, fmt.Errorf("import %s: %w", path, err)
}
if pkg != nil {
im.imports[path] = pkg
return pkg, nil
}
return nil, fmt.Errorf("not found %s", path)
}