Standard library / go/types
go/types.Struct.NumFields()
Number of fields. Expected stdout: '1\n'.
Formal Syntax & Structure
go syntaxgo
func (s *Struct) NumFields() intReturn Value
int
Number of fields.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { t := types.NewStruct([]*types.Var{types.NewField(0, nil, "X", types.Typ[types.Int], false)}, []string{"json:x"}) fmt.Println(t.NumFields())}