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
+36k Golang : Get file last modified date and time
+6.5k Golang : Convert an executable file into []byte example
+5.2k Golang : Print instead of building pyramids
+5.3k Javascript : Shuffle or randomize array example
+9.6k Golang : Validate IPv6 example
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+7.7k Golang : get the current working directory of a running program
+21.6k Golang : GORM create record or insert new record into database example
+13.6k Android Studio : Password input and reveal password example
+30.4k Golang : How to redirect to new page with net/http?
+7.1k Golang : Array mapping with Interface