forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gopath.go
45 lines (41 loc) · 1.46 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
42
43
44
45
package resolvers
import (
"fmt"
"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) {
fmt.Printf("### name -> %+v\n", name)
if g.RecursiveResolver == nil {
g.RecursiveResolver = &RecursiveResolver{
Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path),
}
}
fmt.Printf("### g.RecursiveResolver -> %+v\n", g.RecursiveResolver)
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) {
fmt.Printf("### name -> %+v\n", name)
if g.RecursiveResolver == nil {
g.RecursiveResolver = &RecursiveResolver{
Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path),
}
}
return g.RecursiveResolver.Resolve(name)
}