Golang go/ast.FuncLit type examples

package go/ast

A FuncLit node represents a function literal.

Golang go/ast.FuncLit type usage examples

Example 1:

 blockStatement := &ast.BlockStmt{List: testFunc.Body.List}
 fieldList := &ast.FieldList{}
 funcType := &ast.FuncType{Params: fieldList}
 funcLit := &ast.FuncLit{Type: funcType, Body: blockStatement}

Example 2:

 var  e ast.Expr
 ...
 switch e := e.(type) {
 case *ast.FuncLit:
 panic("encounter a function literal")

Reference :

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

Advertisement