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
+9k Golang : Capture text return from exec function example
+17.1k Golang : XML to JSON example
+14.4k Golang : How to filter a map's elements for faster lookup
+4.7k Javascript : Access JSON data example
+9.6k Golang : Read file with ioutil
+12.5k Golang : "https://" not allowed in import path
+6.7k Golang : Experimental emojis or emoticons icons programming language
+6.7k Golang : Output or print out JSON stream/encoded data
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+10k Golang : Read file and convert content to string
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer