Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Sudo ¶
Sudo takes a reflect.Value where CanSet is false, and turns it into one where CanSet is true.
Example ¶
package main
import (
"fmt"
"reflect"
"github.com/zeebo/sudo"
)
func main() {
var s struct{ x int }
x := reflect.ValueOf(&s).Elem().FieldByName("x")
// Because x went through an unexported field, we can't set it.
fmt.Println(x.CanSet(), s.x)
// But if we Sudo the reflect.Value
x = sudo.Sudo(x)
// then our wildest dreams will come true.
x.SetInt(10)
fmt.Println(x.CanSet(), s.x)
}
Output: false 0 true 10
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.