News for hackers. Stuff that matters.
Re:Deadcode: Finding unreachable functions in Go by zimpenfish on Tuesday January 23, 2024 @02:50PM (#39108757)
`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

Re:Deadcode: Finding unreachable functions in Go by erik_seaberg on Tuesday January 23, 2024 @03:51PM (#39109616)
Yeah, 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).
Re:Deadcode: Finding unreachable functions in Go by zimpenfish on Tuesday January 23, 2024 @05:19PM (#39110761)
You 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 demonstrates this, I think?