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
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+13.9k Golang : Get dimension(width and height) of image file
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+9.2k Golang : Generate Codabar
+5.9k Golang : Use NLP to get sentences for each paragraph example
+19.9k Golang : Count JSON objects and convert to slice/array
+6k Golang : How to verify input is rune?
+6.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+6.9k Golang : Normalize email to prevent multiple signups example
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+13.6k Golang : Query string with space symbol %20 in between
+4.7k Unix/Linux : How to pipe/save output of a command to file?