2 ms·
`MethodByName`[0] allows you to find a method on a struct but I'm assuming you must mean a generic package-level function rather than a method? [0] https://pkg
by zimpenfish 3y ago
`MethodByName`[0] allows you to find a method on a struct but I'm assuming you must mean a generic package-level function rather than a method?
[0] https://pkg.go.dev/reflect#Value.MethodByName https://pkg.go.dev/reflect#Value.MethodByName
- erik_seaberg 3y agoYeah, you can look up a method but only if you already have the receiver’s type (which you also can’t look up by name, or by listing a package).
- zimpenfish 3y agoYou don't need the receiver's type because you're calling `MethodByName` on a `reflect.Value` which you can construct from any receiver. https://go.dev/play/p/hg-ugl7i0ei https://go.dev/play/p/hg-ugl7i0ei demonstrates this, I think?