package main
import (
"bytes"
"fmt"
"go/ast"
"go/parser"
"go/printer"
"go/token"
)
func main() {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "./demo.go", nil, parser.ParseComments)
if err != nil {
return
}
// 打印语法树
ast.Print(fset, f)
var buf bytes.Buffer
printer.Fprint(&buf, fset, f)
fmt.Println(buf.String())
}