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
+10.6k Golang : Bubble sort example
+12.2k Golang : Detect user location with HTML5 geo-location
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+12.8k Golang : Convert int(year) to time.Time type
+7.5k Golang : How to stop user from directly running an executable file?
+30.5k Get client IP Address in Go
+9.8k Golang : Format strings to SEO friendly URL example
+6.9k Default cipher that OpenSSL used to encrypt a PEM file
+10.8k PHP : Convert(cast) bigInt to string
+30k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+9.7k Random number generation with crypto/rand in Go
+8.1k Golang : Variadic function arguments sanity check example