Golang go/ast.DeferStmt type, End() and Pos() functions examples
package go/ast
A DeferStmt node represents a defer statement.
Golang go/ast.DeferStmt type, End() and Pos() functions 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.DeferStmt:
return "defer statement"
...
}
Example 2:
func checkCurrentPosition(node ast.Node) string {
n := node.(*ast.DeferStmt)
endpos := n.End()
pospos := n.Pos()
if pospos != endpos {
return "not yet"
}
}
References :
http://golang.org/pkg/go/ast/#DeferStmt
Advertisement
Something interesting
Tutorials
+8.8k Golang : HTTP Routing with Goji example
+6.3k Javascript : Generate random key with specific length
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+27.5k Golang : dial tcp: too many colons in address
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+16.3k Golang : convert string or integer to big.Int type
+12.3k Golang : List running EC2 instances and descriptions
+19.2k Golang : Delete item from slice based on index/key position
+6.6k Golang : How to validate ISBN?
+6k Linux/MacOSX : Search for files by filename and extension with find command
+22.9k Golang : Test file read write permission example