Some code I’m trying to grok has in it sbot.Network.Serve(ctx)
which I assume means the “Serve” method receives whatever type the “Network” field is, in whatever struct type “sbot” is. My question is how would I reliably find out the source code where a method like “Serve” came from? I don’t know if I’m doing it right.
What I did was this: sbot is created with “mksbot.New()” and “mksbot” lets lets me know which module it’s from, thus I can find the source. As the module has about 20 files in it, I have to blindly rummage through them to tell exactly where the struct is defined, or New() for that matter, but it’s findable. Having found it, I can do the same for sbot.Network, until I find the struct definition, and in the same file is a “Serve()” function receiving that type.
If I see something like obj.Field.Method(...)
is it guaranteed that Method()
is defined in the same file as the type of obj.Field?
Or is it at least guaranteed that Method()
is defined in the same directory as it? Is there some standard to the filename in that directory where things are located? In the “ssb” example, they’re located in a file named “new.go” but is that just arbitrary convention?
I’m worried that someone could define a method that receives a given type, in a totally independent third party module from that type. Since methods are not qualified with module namespace identifiers, there would be no way to find out which module that method came from, and thus no way to find the method’s source, outside of grep -drecurse ~/go/pkg/mod --include '*.go' -e 'func.*Method(
That’s not true, is it?