Created
November 15, 2016 01:57
-
-
Save cep21/1932f1035c03a8464046db30777634c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"bytes" | |
"fmt" | |
"reflect" | |
) | |
func main() { | |
buf := bytes.Buffer{} | |
// Can inspect a private value | |
fmt.Println("Current offset ", reflect.ValueOf(buf).FieldByName("off").Int()) | |
// Setting it will panic. See Value.CanSet | |
reflect.ValueOf(buf).FieldByName("off").Set(reflect.ValueOf(1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment