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
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+10k Golang : Read file and convert content to string
+8.9k Golang : Find network service name from given port and protocol
+10.2k Golang : Check a web page existence with HEAD request example
+9.9k Golang : Turn string or text file into slice example
+11.6k Golang : Surveillance with web camera and OpenCV
+5.7k Golang : Frobnicate or tweaking a string example
+8.1k Golang : HTTP Server Example
+10.6k Golang : Select region of interest with mouse click and crop from image
+8.8k Golang : Gorilla web tool kit schema example
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account