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
+18.5k Golang : Example for RSA package functions
+11.5k Golang : Change date format to yyyy-mm-dd
+8.3k Useful methods to access blocked websites
+6.9k Golang : How to solve "too many .rsrc sections" error?
+6.9k Golang : Decode XML data from RSS feed
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+13.9k Golang : How to check if a file is hidden?
+5.3k Javascript : Change page title to get viewer attention
+5.6k Python : Print unicode escape characters and string
+9.3k Golang : Temperatures conversion example
+12k Golang : Clean formatting/indenting or pretty print JSON result