Golang go/ast.MergePackageFiles() function example
package go/ast
MergePackageFiles creates a file AST by merging the ASTs of the files belonging to a package. The mode flags control merging behavior.
Golang go/ast.MergePackageFiles() function usage example
// from https://github.com/chuckpreslar/gofer/blob/master/gofer.go
func parsePackages(packages map[string]*ast.Package, dir string) {
for _, pkg := range packages {
file := ast.MergePackageFiles(pkg, ast.FilterImportDuplicates) // <-- here
if isGoferTaskFile(file) {
imprtPath := strings.TrimPrefix(strings.Replace(dir, goPath, "", 1), SourcePrefix)
templateData.Imports = append(templateData.Imports, imprt{imprtPath})
}
}
}
References :
Advertisement
Something interesting
Tutorials
+24k Golang : Call function from another package
+20.7k Golang : Saving private and public key to files
+13.7k Golang : Check if an integer is negative or positive
+21.1k Golang : Convert(cast) string to rune and back to string example
+14.9k Golang : Basic authentication with .htpasswd file
+11k Golang : Generate random elements without repetition or duplicate
+10.4k Golang : Meaning of omitempty in struct's field tag
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+14.4k Golang : Parsing or breaking down URL
+10.1k Golang : Compare files modify date example
+7k Golang : Find the shortest line of text example
+11.1k Golang : Simple image viewer with Go-GTK