forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gopath.go
41 lines (37 loc) · 1.3 KB
/
gopath.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
package resolvers
import (
"os"
"path/filepath"
)
// GoPathResolver will search your entire $GOPATH to find the file
// in question. I wouldn't really recommend using this approach. It's
// very very slow the first you try to find a file, and there is no
// guarantees of finding the right now.
type GoPathResolver struct {
Path string
*RecursiveResolver
}
// Read will search your entire $GOPATH to find the file
// in question. I wouldn't really recommend using this approach. It's
// very very slow the first you try to find a file, and there is no
// guarantees of finding the right now.
func (g *GoPathResolver) Read(name string) ([]byte, error) {
if g.RecursiveResolver == nil {
g.RecursiveResolver = &RecursiveResolver{
Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path),
}
}
return g.RecursiveResolver.Read(name)
}
// Resolve will search your entire $GOPATH to find the file
// in question. I wouldn't really recommend using this approach. It's
// very very slow the first you try to find a file, and there is no
// guarantees of finding the right now.
func (g *GoPathResolver) Resolve(name string) (string, error) {
if g.RecursiveResolver == nil {
g.RecursiveResolver = &RecursiveResolver{
Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path),
}
}
return g.RecursiveResolver.Resolve(name)
}