github.com/rotblauer/buffalo@v0.7.1-0.20170112214545-7aa55ef80dd3/render/resolvers/gopath.go (about) 1 package resolvers 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 ) 8 9 // GoPathResolver will search your entire $GOPATH to find the file 10 // in question. I wouldn't really recommend using this approach. It's 11 // very very slow the first you try to find a file, and there is no 12 // guarantees of finding the right now. 13 type GoPathResolver struct { 14 Path string 15 *RecursiveResolver 16 } 17 18 // Read will search your entire $GOPATH to find the file 19 // in question. I wouldn't really recommend using this approach. It's 20 // very very slow the first you try to find a file, and there is no 21 // guarantees of finding the right now. 22 func (g *GoPathResolver) Read(name string) ([]byte, error) { 23 fmt.Printf("### name -> %+v\n", name) 24 if g.RecursiveResolver == nil { 25 g.RecursiveResolver = &RecursiveResolver{ 26 Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path), 27 } 28 } 29 fmt.Printf("### g.RecursiveResolver -> %+v\n", g.RecursiveResolver) 30 return g.RecursiveResolver.Read(name) 31 } 32 33 // Resolve will search your entire $GOPATH to find the file 34 // in question. I wouldn't really recommend using this approach. It's 35 // very very slow the first you try to find a file, and there is no 36 // guarantees of finding the right now. 37 func (g *GoPathResolver) Resolve(name string) (string, error) { 38 fmt.Printf("### name -> %+v\n", name) 39 if g.RecursiveResolver == nil { 40 g.RecursiveResolver = &RecursiveResolver{ 41 Path: filepath.Join(os.Getenv("GOPATH"), "src", g.Path), 42 } 43 } 44 return g.RecursiveResolver.Resolve(name) 45 }