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
+21.8k SSL : How to check if current certificate is sha1 or sha2
+5.7k Unix/Linux/MacOSx : Get local IP address
+7.6k Javascript : Push notifications to browser with Push.js
+12k Golang : Convert a rune to unicode style string \u
+43.3k Golang : Convert []byte to image
+10.8k Golang : Command line file upload program to server example
+13.6k Golang : Qt progress dialog example
+19.2k Golang : Check if directory exist and create if does not exist
+7.5k Golang : Dealing with struct's private part
+28k Golang : Move file to another directory
+15k Golang : How do I get the local IP (non-loopback) address ?