Your go routine is like a little process in your main application. Don’t expect to return values from go routine with return instruction Eventualy use a global variable or a channel like in this example
Looks to me you get an error, because you have an anonymous function returning a value, that go is not expecting to get, and doesn’t know how to handle. Why don’t you name the function and handle the returns accordingly ? You would have to follow the convention that a function needs to declare what is going to return func() ( return types) . If that is not an option, one could use global variables and change their value before the return is triggered.