// VisibleFields returns all the visible fields in t, which must be a // struct type. A field is defined as visible if it's accessible // directly with a FieldByName call. The returned fields include fields // inside anonymous struct members and unexported fields. They follow // the same order found in the struct, with anonymous fields followed // immediately by their promoted fields. // // For each element e of the returned slice, the corresponding field // can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index). func VisibleFields(t Type) []StructField { … } type visibleFieldsWalker … // walk walks all the fields in the struct type t, visiting // fields in index preorder and appending them to w.fields // (this maintains the required ordering). // Fields that have been overridden have their // Name field cleared. func (w *visibleFieldsWalker) walk(t Type) { … }