| 10 | ) |
| 11 | |
| 12 | func Get(packageName string) (m map[string]string, err error) { |
| 13 | config := &packages.Config{ |
| 14 | Mode: packages.NeedTypes | packages.NeedTypesInfo | packages.NeedSyntax, |
| 15 | Tests: true, |
| 16 | } |
| 17 | pkgs, err := packages.Load(config, packageName) |
| 18 | if err != nil { |
| 19 | err = fmt.Errorf("error loading package %s: %w", packageName, err) |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | // Add the comments to the definitions. |
| 24 | m = make(map[string]string) |
| 25 | for _, pkg := range pkgs { |
| 26 | for _, file := range pkg.Syntax { |
| 27 | processFile(packageName, pkg, file, m) |
| 28 | } |
| 29 | } |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | func processFile(packageName string, pkg *packages.Package, file *ast.File, m map[string]string) { |
| 34 | var lastComment string |