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
+18.5k Golang : Send email with attachment
+5k Golang : micron to centimeter example
+7.3k Golang : alternative to os.Exit() function
+13.4k Golang : Verify token from Google Authenticator App
+13.1k Golang : List objects in AWS S3 bucket
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+8.3k Golang : Implementing class(object-oriented programming style)
+7.2k CloudFlare : Another way to get visitor's real IP address
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+13.6k Golang : Strings comparison
+7.7k Golang : Generate human readable password