I want to be able to extract function documentation in addition to a
variety of other information. I have a *packages.Package from
packages.Load. Is there an easy way to get the function documentation
from this. At the moment I am obtaining a *doc.Package using the
following code, but it seems more complicated than necessary and it
returns errors (I think) because I do not have an ast.Importer and I
don't see a place to get one.
files := make(map[string]*ast.File)
for _, f := range pkg.Syntax {
files[
f.Name.Name] = f
}
astPkg, err := ast.NewPackage(pkg.Fset, files, nil, ast.NewScope(nil))
if err != nil {
log.Printf("error preparing docs: %v", err)
}
docs := doc.New(astPkg, pkg.PkgPath, doc.PreserveAST)
Is there a more sensible way to do this?
thanks
Dan