Skip to content

Instantly share code, notes, and snippets.

@cep21
Created November 15, 2016 01:57
Show Gist options
  • Save cep21/1932f1035c03a8464046db30777634c4 to your computer and use it in GitHub Desktop.
Save cep21/1932f1035c03a8464046db30777634c4 to your computer and use it in GitHub Desktop.
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