代码拉取完成,页面将自动刷新
package code
import (
"go/ast"
"strings"
)
// InterfaceSpec is a definition of the interface
type InterfaceSpec struct {
Name string
Methods []*Function
}
// InterfaceSpecs is a group of InterfaceSpec model
type InterfaceSpecs []*InterfaceSpec
// ByName return interface by name Another return value shows whether there is an interface
// with that name exists.
func (intfs InterfaceSpecs) ByName(name string) (*InterfaceSpec, bool) {
for _, intf := range intfs {
if intf.Name == name {
return intf, true
}
}
return nil, false
}
// Param is a model of method parameter
type Param struct {
Name string
Type Type
}
func ExtractInterfaceSpec(spec *ast.TypeSpec, iType *ast.InterfaceType) *InterfaceSpec {
name := spec.Name.Name
intf := InterfaceSpec{
Name: name,
}
for _, method := range iType.Methods.List {
funcType, ok := method.Type.(*ast.FuncType)
if !ok {
continue
}
var methodName string
for _, n := range method.Names {
methodName = n.Name
break
}
var comments []string
if method.Doc != nil {
for _, comment := range method.Doc.List {
commentRunes := []rune(comment.Text)
commentText := strings.TrimSpace(string(commentRunes[2:]))
comments = append(comments, commentText)
}
}
meth := ExtractFunction(methodName, comments, funcType)
intf.Methods = append(intf.Methods, meth)
}
return &intf
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。