On Sat, Apr 11, 2020 at 7:59 PM Tanmay Das <tanmaymi...@gmail.com> wrote:

> Say you have a struct Foo and you access fields and call methods on it as
> you normally would. But is it possible to execute a hook before or after
> that field access or method call? A good scenario will be:
>
> The user calls non-existent method foo.Bar() or accesses non-existent
> field foo.Bar. If they don't exist, I want to:
> a) In case of a method call: forward that call to foo.Baz()
> b) In case of field access: set the foo.Bar at runtime with some value
>

No, as far as I know. You're looking for a language like Python, which I
love, but that isn't the Go model of behavior. This also seems like a
http://xyproblem.info/ question. What is it you really want to do? Are you
trying to mock something for a unit test?

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-Qczxc%3DAC2JziPziTyWDR3gEB8eGYW9zQ_nFP95GpJxw%40mail.gmail.com.

Reply via email to