https://github.com/bradleyjkemp/monkey
Tampering with unexported fields made easy
https://github.com/bradleyjkemp/monkey
go golang monkey-patching
Last synced: 10 months ago
JSON representation
Tampering with unexported fields made easy
- Host: GitHub
- URL: https://github.com/bradleyjkemp/monkey
- Owner: bradleyjkemp
- License: mit
- Created: 2018-06-26T17:17:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-22T15:40:00.000Z (about 6 years ago)
- Last Synced: 2025-03-24T16:51:53.065Z (10 months ago)
- Topics: go, golang, monkey-patching
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monkey [](https://travis-ci.org/bradleyjkemp/monkey) [](https://coveralls.io/github/bradleyjkemp/monkey?branch=master) [](https://goreportcard.com/report/github.com/bradleyjkemp/monkey) [](https://godoc.org/github.com/bradleyjkemp/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:
```go
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:
```go
lib := CoolLibraryConstructor()
coolLibraryPatch := struct {
usefulInternalLogs io.Writer
}{
os.Stdout
}
monkey.Patch(&lib, &coolLibraryPatch)
```
Now your useful internal logs will be written to os.Stdout!