Golang go/ast.FieldList type, End(), NumFields() and Pos() functions example
package go/ast
A FieldList represents a list of Fields, enclosed by parentheses or braces.
NumFields returns the number of (named and anonymous fields) in a FieldList.
Golang go/ast.FieldList type, End(), NumFields() 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.FieldList:
return "field/method/parameter list"
...
}
Example 2:
func checkCurrentPosition(node ast.Node) string {
n := node.(*ast.FieldList)
endpos := n.End()
pospos := n.Pos()
if pospos != endpos {
return "not yet"
}
}
Example 3:
var sig *ast.FuncType
res := sig.Results
n := res.NumFields()
if n == 0 {
// do something
}
Reference :
http://golang.org/pkg/go/ast/#FieldList
http://golang.org/pkg/go/ast/#FieldList.NumFields
Advertisement
Something interesting
Tutorials
+8.4k Golang : Convert word to its plural form example
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+13.4k Golang : Verify token from Google Authenticator App
+24k Golang : Call function from another package
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+8.3k Useful methods to access blocked websites
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+7.7k Gogland : Where to put source code files in package directory for rookie
+5.8k Golang : Launching your executable inside a console under Linux
+4.7k Chrome : How to block socketloop.com links in Google SERP?