Golang go/ast.Field type, End() and Pos() functions examples
package go/ast
A Field represents a Field declaration list in a struct type, a method list in an interface type, or a parameter/result declaration in a signature.
Golang go/ast.Field type, End() and Pos() functions usage examples
Example 1:
func NodeDescription(n ast.Node) string {
switch n := n.(type) {
case *ast.ArrayType:
return "array type"
case *ast.Field:
// Can be any of these:
// struct {x, y int} -- struct field(s)
// struct {T} -- anon struct field
// interface {I} -- interface embedding
// interface {f()} -- interface method
// func (A) func(B) C -- receiver, param(s), result(s)
return "field/method/parameter"
...
}
Example 2:
func checkCurrentPosition(node ast.Node) string {
n := node.(*ast.Field)
endpos := n.End()
pospos := n.Pos()
if pospos != endpos {
return "not yet"
}
}
Example 3:
func checkFieldTag(f *File, node ast.Node) {
field := node.(*ast.Field)
if field.Tag == nil {
return
}
...
}
References :
http://golang.org/pkg/go/ast/#Field
Advertisement
Something interesting
Tutorials
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+8.8k Golang : Heap sort example
+18k Golang : Get all upper case or lower case characters from string example
+9.2k Golang : How to control fmt or log print format?
+8.7k Golang : Combine slices but preserve order example
+4.1k Javascript : Empty an array example
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+8k Golang : Get all countries phone codes
+6.1k nginx : force all pages to be SSL
+18.4k Golang : How to remove certain lines from a file
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+10.8k Android Studio : Checkbox for user to select options example