Using reflection we can list all fields of a struct.
https://codeeval.dev/gist/53c503fa4bae864f9fbbc670d32506ad
Using reflection we can only access values (v.Interface{}
) of exported fields.
Exported fields are fields with names starting with upper case (FirstName
and Age
are exported, lastName
is not).
Field is exported if reflect.StructField.PkgPath == ""
.
Inspecting a struct is inherently recursive process.
You have to chase pointers and recurse into embedded structures.
In real programs inspecting structures using reflections would be recursive.