Golang go/parser.ParseDir() function example
package go/parser
ParseDir calls ParseFile for all files with names ending in ".go" in the directory specified by path and returns a map of package name -> package AST with all the packages found.
If filter != nil, only the files with os.FileInfo entries passing through the filter (and ending in ".go") are considered. The mode bits are passed to ParseFile unchanged. Position information is recorded in fset.
If the directory couldn't be read, a nil map and the respective error are returned. If a parse error occurred, a non-nil but incomplete map and the first error encountered are returned.
Golang go/parser.ParseDir() function usage example
var pkgRealpath, pkgpath string
fileSet := token.NewFileSet()
astPkgs, err := parser.ParseDir(fileSet, pkgRealpath, func(info os.FileInfo) bool {
name := info.Name()
return !info.IsDir() && !strings.HasPrefix(name, ".") && strings.HasSuffix(name, ".go")
}, parser.ParseComments)
References :
Advertisement
Something interesting
Tutorials
+23.5k Golang : Get ASCII code from a key press(cross-platform) example
+5.1k Golang : Display packages names during compilation
+9k Golang : Go as a script or running go with shebang/hashbang style
+6.1k Golang : Debug with Godebug
+10.4k Golang : Generate random integer or float number
+11.6k Golang : Display a text file line by line with line number example
+33k Golang : How to check if a date is within certain range?
+8.3k Golang : Check if integer is power of four example
+16.1k Golang : Generate universally unique identifier(UUID) example
+7.1k Nginx : How to block user agent ?
+6.9k Mac/Linux/Windows : Get CPU information from command line
+9.4k Facebook : Getting the friends list with PHP return JSON format