Standard library / reflect
reflect.VisibleFields()
List fields accessible by FieldByName, including promoted and unexported fields. Visibility does not imply settability. Expected stdout: 'Inner\nX\nY\n'.
Formal Syntax & Structure
go syntaxgo
func VisibleFields(t Type) []StructFieldParameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | Type | Target or element type, as specified by the operation. |
Return Value
[]StructField
List fields accessible by FieldByName, including promoted and unexported fields.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { type Inner struct{ X int } type Outer struct { Inner Y string } for _, f := range reflect.VisibleFields(reflect.TypeOf(Outer{})) { fmt.Println(f.Name) }}