Golang go/ast.Fprint() function example
package go/ast
Fprint prints the (sub-)tree starting at AST node x to w. If fset != nil, position information is interpreted relative to that file set. Otherwise positions are printed as integer values (file set specific offsets).
A non-nil FieldFilter f may be provided to control the output: struct fields for which f(fieldname, fieldvalue) is true are printed; all others are filtered from the output. Unexported struct fields are never printed.
Golang go/ast.Fprint() function usage example
...
var fset = token.NewFileSet()
file, err := parser.ParseFile(fset, "src.go", src, 0)
if err != nil {
fmt.Println(err)
}
var before bytes.Buffer
ast.Fprint(&before, fset, file, nil) // <-- here
...
Reference :
Advertisement
Something interesting
Tutorials
+19.4k Golang : Fix cannot download, $GOPATH not set error
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+9.1k Golang : Handle sub domain with Gin
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+31.5k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+14.8k Golang : Normalize unicode strings for comparison purpose
+17.8k Golang : Defer function inside init()
+14.3k Golang : How to shuffle elements in array or slice?
+35.9k Golang : Integer is between a range
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+7.3k Golang : alternative to os.Exit() function
+11.1k Golang : How to determine a prime number?