Somone knows about a good monkey patching library

856 views
Skip to first unread message

Ori Newman

unread,
Jan 12, 2020, 1:17:05 PM1/12/20
to golang-nuts
Hi,
I know https://github.com/bouk/monkey , but it has a very restrictive license (it says "I do not give anyone permissions to use this tool for any purpose. Don't use it.").
Someone knows an alternative with a better license?
Thanks in advance

prakash sharma

unread,
Jan 12, 2020, 3:00:31 PM1/12/20
to Ori Newman, golang-nuts

I would suggest to use function as type and replace it at the run time
For more info visit these link:
// now a patch example
oldDoSomething := doSomething
// reset func after completing method
defer func () { doSomething = oldDoSomething}()
doSomething = func(s SomethingInterface) bool {
return true
}

You can use delegation approach as mentioned here:

Hope this helps.




  

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9ef764d2-060d-4451-b1d9-034285e524ee%40googlegroups.com.

Ori Newman

unread,
Jan 12, 2020, 3:24:10 PM1/12/20
to golang-nuts
Hi,
The attached gist can't work for patching methods. And I do not want to use dependency injection. This is a very big project and I'm beyond the point that I can change it to use dependency injection.


On Sunday, January 12, 2020 at 10:00:31 PM UTC+2, prakash sharma wrote:

I would suggest to use function as type and replace it at the run time
For more info visit these link:
// now a patch example
oldDoSomething := doSomething
// reset func after completing method
defer func () { doSomething = oldDoSomething}()
doSomething = func(s SomethingInterface) bool {
return true
}

You can use delegation approach as mentioned here:

Hope this helps.




  

On Sun, 12 Jan, 2020, 11:46 PM Ori Newman, <orine...@gmail.com> wrote:
Hi,
I know https://github.com/bouk/monkey , but it has a very restrictive license (it says "I do not give anyone permissions to use this tool for any purpose. Don't use it.").
Someone knows an alternative with a better license?
Thanks in advance

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.

Jason E. Aten

unread,
Jan 13, 2020, 4:05:26 AM1/13/20
to golang-nuts
If you call through an interface, you get runtime, dynamic dispatch.

Pinkesh Bardiya

unread,
Mar 31, 2021, 1:05:50 PM3/31/21
to golang-nuts
https://github.com/undefinedlabs/go-mpatch


On Monday, January 13, 2020 at 2:35:26 PM UTC+5:30 Jason E. Aten wrote:
If you call through an interface, you get runtime, dynamic dispatch.

This message contains confidential information and is intended only for the individual to whom it is addressed. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and permanently delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, late or incomplete, or could contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version from the sender. Druva, www.druva.com

Reply all
Reply to author
Forward
0 new messages