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 :

https://github.com/chuckpreslar/gofer/blob/master/gofer.go

http://golang.org/pkg/go/ast/#MergePackageFiles

Advertisement