Golang go/ast.BasicLit type examples
package go/ast
A BasicLit node represents a literal of basic type.
Golang go/ast.BasicLit type usage examples
Example 1:
func NodeDescription(n ast.Node) string {
switch n := n.(type) {
case *ast.ArrayType:
return "array type"
case *ast.AssignStmt:
return "assignment"
case *ast.BasicLit:
return "basic literal"
...
}
Example 2:
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)} //<-- here
itBlockIdent := &ast.Ident{Name: "It"}
callExpr := &ast.CallExpr{Fun: itBlockIdent, Args: []ast.Expr{basicLit, funcLit}}
return &ast.ExprStmt{X: callExpr}
}
Reference :
Advertisement
Something interesting
Tutorials
+13.6k Android Studio : Password input and reveal password example
+10.1k Golang : Edge detection with Sobel method
+8.9k Golang : Find network service name from given port and protocol
+29.5k Golang : How to create new XML file ?
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+10.7k Golang : Get currencies exchange rates example
+15.8k Golang : Get digits from integer before and after given position example
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+6k Linux/MacOSX : Search for files by filename and extension with find command
+16.1k Golang : Generate universally unique identifier(UUID) example
+11.5k Golang : Generate DSA private, public key and PEM files example
+9.9k Golang : ffmpeg with os/exec.Command() returns non-zero status