Golang go/ast.ImportSpec type examples

package go/ast

Golang go/ast.ImportSpec type usage examples

Example 1:

 func createImport(name, path string) *ast.ImportSpec {
 return &ast.ImportSpec{
 Name: &ast.Ident{Name: name},
  Path: &ast.BasicLit{Kind: 9, Value: path},
 }
 }

Example 2:

 newImport := &ast.ImportSpec{
 Name: ast.NewIdent(atomicPackageName),
 Path: &ast.BasicLit{
  Kind:  token.STRING,
  Value: fmt.Sprintf("%q", path),
 },
 }

Reference :

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

Advertisement