为什么go/doc不提供方法?
我正试图提取使用该包的各种函数和方法的文档。代码如下所示。问题在于,它只打印/提供packageexported和unexported中的函数,而不提供方法,不管它们是导出的还是未导出的。我还尝试了AllMethods模式,但没有成功。这是虫子还是我遗漏了什么为什么go/doc不提供方法?,go,Go,我正试图提取使用该包的各种函数和方法的文档。代码如下所示。问题在于,它只打印/提供packageexported和unexported中的函数,而不提供方法,不管它们是导出的还是未导出的。我还尝试了AllMethods模式,但没有成功。这是虫子还是我遗漏了什么 pkg := doc.New(mainPkg, "./", doc.AllDecls) for _, vv := range pkg.Funcs { log.Infof("vv.Name %v, vv.Recv %v", vv.
pkg := doc.New(mainPkg, "./", doc.AllDecls)
for _, vv := range pkg.Funcs {
log.Infof("vv.Name %v, vv.Recv %v", vv.Name, vv.Recv, )
}
遍历pkg.Types,并在每个项目上获得其属性
您需要从迭代类型中提取方法,不是funcs。是的……我刚刚开始研究这个……当你发现方法在类型字段中可用时,可能会将它作为一个答案发布出来,这对我来说似乎不合适,所以我不确定它是否值得一个答案。对我来说,它似乎完全正确——方法属于类型,而不是包本身。但是,如果它把你弄糊涂了,它可能会把别人弄糊涂,所以一个答案是好的。
type Type struct {
Doc string
Name string
Decl *ast.GenDecl
// associated declarations
Consts []*Value // sorted list of constants of (mostly) this type
Vars []*Value // sorted list of variables of (mostly) this type
Funcs []*Func // sorted list of functions returning this type
Methods []*Func // sorted list of methods (including embedded ones) of this type
}