1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package main
import (
"fmt"
"go/doc"
"go/parser"
"go/token"
)
// GetFoo comments I can find easely
func GetFoo() {
// Comment I would like to access
test := 1
fmt.Println(test)
}
type (
//comment= user interface
User interface {
// getIt xx
GetIt(id int) int
Get2(id int) error
}
)
func main() {
fset := token.NewFileSet() // positions are relative to fset
d, err := parser.ParseDir(fset, "./", nil, parser.ParseComments)
if err != nil {
fmt.Println(err)
return
}
for k, f := range d {
fmt.Println("package", k)
p := doc.New(f, "./", 2)
for _, t := range p.Types {
fmt.Println("types type", t.Name)
fmt.Println("types docs:", t.Doc)
}
for _, v := range p.Vars {
fmt.Println("vars type", v.Names)
fmt.Println("vars docs:", v.Doc)
}
for _, f := range p.Funcs {
fmt.Println("fs type", f.Name)
fmt.Println("fs docs:", f.Doc)
}
for _, n := range p.Notes {
fmt.Println("body", n[0].Body)
}
}
}
|