Skip to content

Tampering with unexported fields made easy

License

Notifications You must be signed in to change notification settings

bradleyjkemp/monkey

Repository files navigation

monkey Build Status Coverage Status Go Report Card GoDoc

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!

About

Tampering with unexported fields made easy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published