Golang go/printer.Config.Fprint() function example
package go/printer
Fprint "pretty-prints" an AST node to output for a given configuration cfg. Position information is interpreted relative to the file set fset. The node type must be *ast.File, *CommentedNode, []ast.Decl, []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec, or ast.Stmt.
Golang go/printer.Config.Fprint() function usage example
func Process(filename string, src []byte, opt *Options) ([]byte, error) {
if opt == nil {
opt = &Options{Comments: true, TabIndent: true, TabWidth: 8}
}
fileSet := token.NewFileSet()
file, adjust, err := parse(fileSet, filename, src, opt)
if err != nil {
return nil, err
}
...
var buf bytes.Buffer
err = printConfig.Fprint(&buf, fileSet, file) // <-- here
if err != nil {
return nil, err
}
...
References :
https://code.google.com/p/go/source/browse/go/importer/import.go?repo=tools
Advertisement
Something interesting
Tutorials
+15.1k Golang : Get timezone offset from date or timestamp
+27.5k PHP : Count number of JSON items/objects
+7.2k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+17.4k Golang : Find smallest number in array
+13.9k Golang : concatenate(combine) strings
+13.4k Golang : reCAPTCHA example
+35.1k Golang : Strip slashes from string example
+12.2k Golang : Validate email address
+11.8k Golang : How to parse plain email text and process email header?
+12.6k Swift : Convert (cast) Int or int32 value to CGFloat
+4.8k HTTP common errors and their meaning explained
+23.9k Golang : Upload to S3 with official aws-sdk-go package