How to access unexported struct fields
If the struct is addressable, you can use unsafe.Pointer to access the field (read or write) it, like this: rs := reflect.ValueOf(&MyStruct).Elem() rf := rs.Field(n) // rf can’t be read or set. rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() // Now rf can be read and set. See full example on the playground. This use of unsafe.Pointer is … Read more