Search code examples
goabstract-syntax-tree

Go: Get filepath from ast.File


Assume I have:

f, err := parser.ParseFile(fset, srcPath, nil, 0)

How can I get back the srcPath from f?


Solution

  • Use fset.Position(f.Package).Filename to get srcPath from f.