Golang go/ast.FuncDecl type example

package go/ast

A FuncDecl node represents a function declaration.

Golang go/ast.FuncDecl type usage example

 func getFuncName(funcDecl *ast.FuncDecl) string {
 prefix := ""
 if funcDecl.Recv != nil {
 recvType := funcDecl.Recv.List[0].Type
  if recvStarType, ok := recvType.(*ast.StarExpr); ok {
 prefix = "(*" + recvStarType.X.(*ast.Ident).Name + ")"
  } else {
 prefix = recvType.(*ast.Ident).Name
  }
 prefix += "."
  }
  return prefix + funcDecl.Name.Name
 }

References :

https://github.com/revel/revel/blob/master/harness/reflect.go

http://golang.org/pkg/go/ast/#FuncDecl

Advertisement