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
+7.9k Golang : Ways to recover memory during run time.
+17.5k Golang : Clone with pointer and modify value
+6.2k Golang : Extract XML attribute data with attr field tag example
+39.6k Golang : Remove dashes(or any character) from string
+18.4k Golang : How to get hour, minute, second from time?
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+10.6k Golang : Get local time and equivalent time in different time zone
+5.6k Fix fatal error: evacuation not done in time problem
+22.4k Golang : Read directory content with filepath.Walk()
+9.2k Golang : does not implement flag.Value (missing Set method)
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+9.9k Golang : Check if user agent is a robot or crawler example