gpt4 book ai didi

go - 为什么 go/doc 没有提供方法?

转载 作者:IT王子 更新时间:2023-10-29 02:24:04 24 4
gpt4 key购买 nike

我正在尝试使用 go/doc 提取各种函数和方法的文档包裹。代码看起来很像下面。问题是它仅打印/提供包中的功能(导出和未导出),但无论它们是导出还是未导出,都没有方法。我还尝试了 AllMethods 模式但没有成功。这是错误还是我遗漏了什么?

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 并且在每个项目上您可以获得它的 Methods .

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
}

关于go - 为什么 go/doc 没有提供方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28556775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com