Golang go/ast.Print() function examples
package go/ast
Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
Golang go/ast.Print() function usage examples
Example 1 :
fset := token.NewFileSet()
astPkgs, err := parser.ParseDir(fset, dir, nil, 0)
if err != nil {
errorfExit("can not parse package %s, %s", dir, err)
}
for _, pkg := range astPkgs {
ast.Print(fset, pkg)
}
Example 2 : ( from http://golang.org/pkg/go/ast/#Print )
package main
import (
"go/ast"
"go/parser"
"go/token"
)
func main() {
// src is the input for which we want to print the AST.
src := `
package main
func main() {
println("Hello, World!")
}
`
// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := parser.ParseFile(fset, "", src, 0)
if err != nil {
panic(err)
}
// Print the AST.
ast.Print(fset, f)
}
References :
Advertisement
Something interesting
Tutorials
+8.8k Golang : Heap sort example
+10k Golang : Convert octal value to string to deal with leading zero problem
+15.8k Golang : How to login and logout with JWT example
+5.7k Golang : Frobnicate or tweaking a string example
+3.7k Golang : Switch Redis database redis.NewClient
+5.6k PHP : Fix Call to undefined function curl_init() error
+15.8k Golang : Get digits from integer before and after given position example
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+5.2k Python : Create Whois client or function example
+35.1k Golang : Upload and download file to/from AWS S3
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example