Standard library / go/doc
go/doc.PreserveAST
Prevents documentation extraction from modifying the caller’s AST. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
const PreserveAST Mode = 4Working Example
Example Snippetgo
package main
import ( "fmt" "go/ast" "go/doc" "go/parser" "go/token")
func check(e error) { if e != nil { panic(e) }}
func main() { fs := token.NewFileSet() f, e := parser.ParseFile(fs, "demo.go", "package demo;func Work(){}", 0) check(e) _, e = doc.NewFromFiles(fs, []*ast.File{f}, "demo", doc.PreserveAST) check(e) fmt.Println(f.Decls[0].(*ast.FuncDecl).Body != nil)}