Standard library / reflect
reflect.Value.NumField()
Return the count of direct struct fields; non-struct values panic. Expected stdout: '2\n'.
Formal Syntax & Structure
go syntaxgo
func (v Value) NumField() intReturn Value
int
Return the count of direct struct fields; non-struct values panic.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { fmt.Println(reflect.ValueOf(struct { X int Y bool }{}).NumField())}