Golang go/ast.BlockStmt type examples
package go/ast
A BlockStmt node represents a braced statement list.
Golang go/ast.BlockStmt 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.BlockStmt:
return "block"
...
}
Example 2:
var node ast.Node
...
switch n := node.(type) {
var stmt := n.Else.(type)
block := &ast.BlockStmt{
Lbrace: n.Body.End(), // Start at end of the "if" block so the covered part looks like it starts at the "else".
List: []ast.Stmt{stmt},
Rbrace: stmt.End(),
}
n.Else = block
}
...
Reference :
Advertisement
Something interesting
Tutorials
+5.3k Golang : Pad file extension automagically
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+13.9k Golang : How to determine if a year is leap year?
+26.6k Golang : Encrypt and decrypt data with AES crypto
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+8.4k Golang : Convert word to its plural form example
+12.1k Golang : Save webcamera frames to video file
+9.4k Golang : Play .WAV file from command line
+6.9k Golang : Fibonacci number generator examples
+30.8k Golang : Download file example
+12.8k Golang : Listen and Serve on sub domain example