forked from semrush/zenrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_unix.go
44 lines (35 loc) · 791 Bytes
/
import_unix.go
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
// +build !windows
package parser
import (
"fmt"
"os"
"path"
"strings"
)
var vendors []string
func init() {
if pwd, err := os.Getwd(); err != nil {
fmt.Printf("Warning: %s\n", err)
} else {
if fi, err := os.Stat(pwd + "/vendor"); err == nil && fi.IsDir() {
vendors = append(vendors, pwd+"/vendor")
}
}
vendors = append(vendors, strings.Split(os.Getenv("GOPATH"), ":")...)
}
func tryFindPath(fname, dir string) string {
if len(fname) > 0 && fname[0] == '.' {
// path is relative
return path.Clean(path.Join(dir, fname))
}
for _, p := range vendors {
filepath := fname
if !strings.HasPrefix(fname, p) {
filepath = path.Join(p, "src") + "/" + fname
}
if fi, err := os.Stat(filepath); err == nil && fi.IsDir() {
return filepath
}
}
return ""
}