Golang go/ast.Expr type example
package go/ast
All expression nodes implement the Expr interface.
Golang go/ast.Expr type usage example
func createItStatementForTestFunc(testFunc *ast.FuncDecl) *ast.ExprStmt {
blockStatement := &ast.BlockStmt{List: testFunc.Body.List}
fieldList := &ast.FieldList{}
funcType := &ast.FuncType{Params: fieldList}
funcLit := &ast.FuncLit{Type: funcType, Body: blockStatement}
testName := rewriteTestName(testFunc.Name.Name)
basicLit := &ast.BasicLit{Kind: 9, Value: fmt.Sprintf("\"%s\"", testName)}
itBlockIdent := &ast.Ident{Name: "It"}
callExpr := &ast.CallExpr{Fun: itBlockIdent, Args: []ast.Expr{basicLit, funcLit}} // <-- here
return &ast.ExprStmt{X: callExpr}
}
References :
http://golang.org/pkg/go/ast/#Expr
https://github.com/onsi/ginkgo/blob/master/ginkgo/convert/ginkgoastnodes.go
Advertisement
Something interesting
Tutorials
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+16.5k Golang : Get IP addresses of a domain name
+4.6k Linux : sudo yum updates not working
+12.3k Golang : Validate email address
+41.4k Golang : Convert string to array/slice
+5k Golang : Calculate a pip value and distance to target profit example
+37.7k Golang : Comparing date or timestamp
+30.9k error: trying to remove "yum", which is protected
+14k Golang : Human readable time elapsed format such as 5 days ago
+7k Golang : How to call function inside template with template.FuncMap
+10.1k Golang : Compare files modify date example
+5.3k Javascript : Change page title to get viewer attention