Kyle, thanks, that's a very practical alternative solution, and anyone in their right mind would just do that.
However, for the sake of solving a fun challenge and being able to do something that I am currently unable to do, I'd like to try and solve the original problem anyway.
Some leads I got so far:
1. Parsing the .go file where the func is defined can give me the AST, and the anon func will be one of the *ast.FuncLit types. It might be tricky to figure out which one it is, if there are many of them and the assignment logic isn't trivial.
2. If I were to execute the anon func, it's possible to get its pc (program counter). e.g. func() { pc, _, _, _ := runtime.Caller(0); println(pc); ... } Then you can do file, line := runtime.FuncForPC(pc).FileLine(pc) to get the line where the func is defined. This can help greatly with finding the correct *ast.FuncLit in the AST.
Is there any way to find the pc of a given func entry point without resorting to calling it and doing runtime.Caller(0)?