Created
August 6, 2020 14:43
-
-
Save podhmo/ac9ae4dd54cc8a3e1e9cb7571b37405a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
"unsafe" | |
) | |
type S struct { | |
Exported int | |
unexported int | |
} | |
func main() { | |
s := &S{Exported: 20, unexported: 10} | |
rv := reflect.ValueOf(s).Elem() | |
rf := rv.FieldByName("unexported") | |
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() | |
fmt.Println(rf.Interface()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment