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
+6k Golang : Compound interest over time example
+48.1k Golang : How to convert JSON string to map and slice
+5.4k Golang : What is StructTag and how to get StructTag's value?
+22.2k Golang : Securing password with salt
+15.3k nginx: [emerg] unknown directive "ssl"
+31.7k Golang : How to convert(cast) string to IP address?
+5.6k Python : Print unicode escape characters and string
+15.4k Golang : Find location by IP address and display with Google Map
+7.3k Golang : File system scanning
+30.9k Golang : Interpolating or substituting variables in string examples
+19.8k Golang : Append content to a file
+51.9k Golang : How to get time in milliseconds?