Re: [go-nuts] Intercepting field access and method call

2020-04-13 Thread Tanmay Das
Thanks for the clarification, Brian! On Monday, April 13, 2020 at 2:56:49 PM UTC+6, Brian Candler wrote: > > On Sunday, 12 April 2020 18:12:16 UTC+1, Tanmay Das wrote: >> >> this is not my first statically typed language, I know a little bit of C >> and Java. I was under the impression that Go

Re: [go-nuts] Intercepting field access and method call

2020-04-13 Thread Brian Candler
On Sunday, 12 April 2020 18:12:16 UTC+1, Tanmay Das wrote: > > this is not my first statically typed language, I know a little bit of C > and Java. I was under the impression that Go is capable of some dynamic > behavior. Maybe things like Go's type inference, duck typing, empty > interface{}

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread robert engels
You probably want to use interfaces. You can do a lot of “seemingly dynamic” programming with interfaces. There are statically typed languages that pretty dynamic - Java with reflection and proxies - but Go is also statically compiled which makes the options limited - which is usually a good

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread Tanmay Das
Hi Jake, Thanks for the wishes. BTW, this is not my first statically typed language, I know a little bit of C and Java. I was under the impression that Go is capable of some dynamic behavior. Maybe things like Go's type inference, duck typing, empty interface{} led me to believe that. All these

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread Brian Candler
And just to add, since you mentioned fields on a struct: all fields are initialized to their "zero value" (which for example is 0 for an int, or empty string for a string). So there is no such thing as a non-existent or uninitialized field. -- You received this message because you are

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread Jake Montgomery
It sounds like maybe this is your first statically typed language. Go is statically typed, which means that the scenarios you are talking about can not happen. That is by design, and has huge benefits for code reliability, and also readability. If you call a function that takes a Foo struct as

Re: [go-nuts] Intercepting field access and method call

2020-04-12 Thread Nedim Sabic
Hi, You could achieve function / method interception with ebpf and uprobes. You can find a thorough tutorial here: https://sematext.com/blog/ebpf-userland-apps/ El dom., 12 abr. 2020 6:20, Tanmay Das escribió: > Hi, thanks for your reply. I am still in the learning phase and when I > learn the

Re: [go-nuts] Intercepting field access and method call

2020-04-11 Thread Tanmay Das
Hi, thanks for your reply. I am still in the learning phase and when I learn the usage of a new tool I try to keep notes of *what's allowed *and *what's not allowed* by that tool. That's all :) So at this moment, it's not possible for me to come up with a concrete production-level use case.

Re: [go-nuts] Intercepting field access and method call

2020-04-11 Thread Kurtis Rader
On Sat, Apr 11, 2020 at 7:59 PM Tanmay Das 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

[go-nuts] Intercepting field access and method call

2020-04-11 Thread Tanmay Das
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