monkey
monkey copied to clipboard
Tampering with unexported fields made easy
monkey
Ever wanted to tamper with the value of an unexported field? This library lets you create a small patch value which can be applied to modify unexported fields regardless of how deeply nested they are.
Usage
Say you have a struct like so:
type CoolLibrary struct {
usefulInternalLogs io.Writer
...
...
}
But you want access to the internal logs which can't be configured to write to a location of your choice.
You could fork the library and add this feature or just use Monkey to patch this field:
lib := CoolLibraryConstructor()
coolLibraryPatch := struct {
usefulInternalLogs io.Writer
}{
os.Stdout
}
monkey.Patch(&lib, &coolLibraryPatch)
Now your useful internal logs will be written to os.Stdout!