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
+12.2k Golang : Simple client-server HMAC authentication without SSL example
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+19.4k Golang : Fix cannot download, $GOPATH not set error
+10.2k Golang : Random Rune generator
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+19.3k Golang : Get RGBA values of each image pixel
+10.9k Golang : Create Temporary File
+6.9k Golang : How to solve "too many .rsrc sections" error?
+5.9k Unix/Linux : How to open tar.gz file ?
+43.2k Golang : Convert []byte to image
+7.9k Golang : Gomobile init produce "iphoneos" cannot be located error