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
+6k Javascript : Get operating system and browser information
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+9k Golang : automatically figure out array length(size) with three dots
+5k Golang : Constant and variable names in native language
+27.5k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+9.5k Golang : Changing a RGBA image number of channels with OpenCV
+12.8k Golang : http.Get example
+7.7k Golang : How to execute code at certain day, hour and minute?
+4.5k Java : Generate multiplication table example
+23.5k Golang : Check if element exist in map
+30.4k Golang : How to verify uploaded file is image or allowed file types
+21.5k Golang : How to read float value from standard input ?