[Go] How to query for a function that is passed as a variable? #13159
-
Example: type A struct {
Handler func(int)
}
var as = []A{
{
Handler: someFunc
},
{
Handler: someFunc2
},
...
}
for i := 0; i < len(as); i++{
as[i].Handler(i)
} I want the query to return all the functions that are being called by the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 20 replies
-
How I am currently solving this is by querying for all the However, this method is not flexible at all: e.g. every change to structure of the variable |
Beta Was this translation helpful? Give feedback.
Depending on how precise you want to be, here's a sink that identifies any write to the field
MethodDesc.Handler
:However perhaps you're concerned that not all MethodDesc.Handlers end up passed to RegisterService? In that case we can make our sink any argument to RegisterService:
...then…