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
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+22.2k Golang : Securing password with salt
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+55.3k Golang : Unmarshal JSON from http response
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+8.4k Golang : Ackermann function example
+16.5k Golang : Execute terminal command to remote machine example
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+10k Golang : Read file and convert content to string
+6.3k Golang : How to get capacity of a slice or array?
+4k Detect if Google Analytics and Developer Media are loaded properly or not