I was wondering why this is valid go code:
func FindUserInfo(id string) (Info, bool) {
it, present := all[id]
return it, present
}
but
I'm no Go expert but I believe you are getting compile time error when you are trying to return the array i.e. return all[id]
. The reason could be because the functions return type is specially mentioned as (Info, bool)
and when you are doing return all[id]
it can't map the return type of all[id]
to (Info, bool)
.
However the solution mentioned above, the variables being returned i
and ok
are the same that are mentioned in the return type of the function (i Info, ok bool)
and hence the compiler knows what it's returning as opposed to just doing (i Info, ok bool)
.