How do I print out all variables that are captured by a closure? For example:
func myScope() {
users := GetUsers("John")
services := GetServices("Movies")
allVariablesString := func() string {
return PrintAllCapturesWithoutSpecified()
}()
}
I plan to utilize this idea if possible to log any involved values within the scope of an error without manually specify each variable.
This is impossible in Go. You can't ask for your surrounding environment in a closure. It's there to use, but you can't view/read it. You could do something weird like have them in a struct and view your struct, but depending on what you do, that could get very messy and non-idiomatic.