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
+5.6k Grep : How to grep for strings inside binary data
+7.3k Golang : Emulate NumPy way of creating matrix example
+36.4k Golang : Read a text file and replace certain words
+8.5k Golang : How to get garbage collection data?
+6.1k Golang : Levenshtein distance example
+16.4k Golang : Defer function inside init()
+6.5k Golang : How to handle file size larger than available memory panic issue
+11.7k Golang : Transform comma separated string to slice example
+10k Golang : Generate random elements without repetition or duplicate
+9.8k Golang : Replace a parameter's value inside a configuration file example
+15k Golang : Generate universally unique identifier(UUID) example
+5k Golang : Use NLP to get sentences for each paragraph example