...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package swag
16
17 import (
18 "os"
19 "path/filepath"
20 "runtime"
21 "strings"
22 )
23
24 const (
25
26 GOPATHKey = "GOPATH"
27 )
28
29
30 func FindInSearchPath(searchPath, pkg string) string {
31 pathsList := filepath.SplitList(searchPath)
32 for _, path := range pathsList {
33 if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil {
34 if _, err := os.Stat(evaluatedPath); err == nil {
35 return evaluatedPath
36 }
37 }
38 }
39 return ""
40 }
41
42
43 func FindInGoSearchPath(pkg string) string {
44 return FindInSearchPath(FullGoSearchPath(), pkg)
45 }
46
47
48 func FullGoSearchPath() string {
49 allPaths := os.Getenv(GOPATHKey)
50 if allPaths == "" {
51 allPaths = filepath.Join(os.Getenv("HOME"), "go")
52 }
53 if allPaths != "" {
54 allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":")
55 } else {
56 allPaths = runtime.GOROOT()
57 }
58 return allPaths
59 }
60
View as plain text