github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/codegen/loaderx/file.go (about) 1 package loaderx 2 3 import ( 4 "go/ast" 5 "go/build" 6 "os" 7 ) 8 9 func FileOf(targetNode ast.Node, files ...*ast.File) *ast.File { 10 for _, file := range files { 11 if file.Pos() <= targetNode.Pos() && file.End() > targetNode.Pos() { 12 return file 13 } 14 } 15 return nil 16 } 17 18 func ResolvePkgImport(pkgImportPath string) string { 19 cwd, _ := os.Getwd() 20 pkg, _ := build.Import(pkgImportPath, cwd, build.FindOnly) 21 return pkg.ImportPath 22 }