As can be seen from my recent posts, I've been playing a lot with the
automatic generation if go programs using go/ast and related packages.
My current problem is that when I use astutil.AddImport.
When I rn the program below, which creates a new ast.File and uses
astutil.AddImport to import to packages into it, the serialization of that
File only includes the first import:
go run add_import.go
package foo
import "fmt"
Has anyone else seen this?
I have added debugging code to my application and that shows that all of
the imports appear as separate ast.ImportSpecs in the same ast.GenDecl.
Here's my test program. The Playground isn't able to import astutil.
*// Test astutil.AddImport*
*package main*
*import "go/ast"*
*import "go/format"*
*import "go/token"*
*import "os"*
*import "golang.org/x/tools/go/ast/astutil"*
*func main() {*
* fset := token.NewFileSet()*
* newAstFile := &ast.File{*
* Name: ast.NewIdent("foo"),*
* Decls: []ast.Decl{},*
* }*
* astutil.AddImport(fset, newAstFile, "fmt")*
* astutil.AddImport(fset, newAstFile, "reflect")*
* format.Node(os.Stdout, fset, newAstFile)*
*}*
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.