代码拉取完成,页面将自动刷新
package code
import "go/ast"
type Function struct {
Name string
Params []Param
Returns []Type
Comments []string
}
type Method struct {
Function
Receiver Receiver
}
type Receiver struct {
Type Type
Name string
}
func ExtractFunction(name string, commonts []string, funcType *ast.FuncType) *Function {
funct := Function{
Name: name,
Comments: commonts,
}
for _, param := range funcType.Params.List {
paramType := getType(param.Type)
if len(param.Names) == 0 {
funct.Params = append(funct.Params, Param{Type: paramType})
continue
}
for _, name := range param.Names {
funct.Params = append(funct.Params, Param{
Name: name.Name,
Type: paramType,
})
}
}
if funcType.Results != nil {
for _, result := range funcType.Results.List {
funct.Returns = append(funct.Returns, getType(result.Type))
}
}
return &funct
}
func ExtractMethod(funcDecl *ast.FuncDecl) *Method {
name := funcDecl.Name.Name
funcType := funcDecl.Type
function := ExtractFunction(name, nil, funcType)
recv := funcDecl.Recv
if recv != nil && len(recv.List) > 0 {
meth := Method{
Function: *function,
Receiver: Receiver{
Type: getType(recv.List[0].Type),
Name: recv.List[0].Names[0].Name,
},
}
return &meth
}
return &Method{
Function: *function,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。