blob: c98710d187a295483f1fa51a7acc3dfad2746418 (
plain)
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
|
package analysisutil
import (
"go/types"
"strings"
)
// RemoVendor removes vendoring infomation from import path.
func RemoveVendor(path string) string {
i := strings.Index(path, "vendor")
if i >= 0 {
return path[i+len("vendor")+1:]
}
return path
}
// LookupFromImports finds an object from import paths.
func LookupFromImports(imports []*types.Package, path, name string) types.Object {
path = RemoveVendor(path)
for i := range imports {
if path == RemoveVendor(imports[i].Path()) {
return imports[i].Scope().Lookup(name)
}
}
return nil
}
|