golang return multiple values issue

后端 未结 5 1032
陌清茗
陌清茗 2021-02-05 08:47

I was wondering why this is valid go code:

func FindUserInfo(id string) (Info, bool) {
    it, present := all[id]
    return it, present
}

but

5条回答
  •  执笔经年
    2021-02-05 09:37

    By default, maps in golang return a single value when accessing a key

    https://blog.golang.org/go-maps-in-action

    Hence, return all[id] won't compile for a function that expects 2 return values.

提交回复
热议问题