You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to propose the ability to set struct functions/methods. I know that #16522 is similar but is not the same, I want to override, and not add.
What did you see instead?
panic: reflect: reflect.Value.Set using unaddressable value
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
Propose: with reflect be able to set struct methods/functions
proposal: reflect: permit setting struct methods/functions
Apr 26, 2019
In general the reflect package lets you do the kinds of things you can do in the language directly. But the language does not permit overriding the methods of an existing type.
My propose on this is create a mocker library for unit tests like we see in other languages.
An other way to do this is create a dummy struct that is composed by the aimed struct that should be mocked and so add methods/functions in order to override those child methods/functions
whould be awesome if one of these 2 approaches is implemented in the reflect pack.
In general it's not possible to do this to a running binary. Function calls have been inlined and otherwise are scattered all over the program, pre-resolved. There's no way to just jam in a new function in place of an existing one. Reflect is about looking at the program, not modifying it.
What version of Go are you using (
go version
)?go version go1.11.5 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/Onjw6KMe0gv
What did you expect to see?
I would like to propose the ability to set struct functions/methods. I know that #16522 is similar but is not the same, I want to override, and not add.
What did you see instead?
panic: reflect: reflect.Value.Set using unaddressable value
The text was updated successfully, but these errors were encountered: