Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unpatch ¶
func Unpatch(target interface{}) bool
Unpatch removes any monkey patch applied to the target. It returns whether the target was patched in the first place.
func UnpatchByName ¶
UnpatchByName removes any monkey patch applied to the target by it's name. TargetName should be the fully-qualified name of the target function or method.
func UnpatchMethod ¶
UnpatchMethod removes any monkey patch applied to the methodName method of the target. It returns whether the method was patched in the first place.
Types ¶
type PatchGuard ¶
type PatchGuard struct {
// contains filtered or unexported fields
}
PatchGuard holds the patch status of a patch target and it's replacement.
func Patch ¶
func Patch(target, replacement interface{}) *PatchGuard
Patch replaces a function with replacement. If target or replacement is not a function their types do not match, it panics.
func PatchByName ¶
func PatchByName(targetName string, replacement interface{}) *PatchGuard
PatchByName replaces a function with replacement by it's name. TargetName should be the fully-qualified name of the target function or method. If the target cannot be found or the replacement type does not match, it panics.
func PatchMethod ¶
func PatchMethod(target interface{}, methodName string, replacement interface{}) *PatchGuard
PatchMethod replaces an target's methodName method with replacement. Replacement should expect the receiver (of type target) as the first argument. If the method cannot be found or the replacement type does not match, it panics.
func (*PatchGuard) Restore ¶
func (p *PatchGuard) Restore()
Restore re-apply the monkey patch to the target if removed. If the patch has already been applied, it's a no-op.
func (*PatchGuard) Unpatch ¶
func (p *PatchGuard) Unpatch()
Unpatch removes the monkey patch of the target.