List fields of a struct

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 == "".

List fields of a struct recursively

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.

https://codeeval.dev/gist/39a6252f4d94d48a7b9f46cc36a54959