返回地图数据结构

huangapple go评论93阅读模式
英文:

Returning maps data structures

问题

我正在尝试弄清楚如何在Go中调用函数时返回一个映射。我似乎找不到任何关于这方面的文档。到目前为止,我尝试了以下方法:

func test() map {
    // 获取授权令牌(POST https://192.168.13.234/aperture/api/users/authorize)
    anotherMap := map[string]string{"a": "b", "c": "d"}
    return anotherMap
}

希望对你有帮助!

英文:

I'm trying to work out how to return a map when calling a function in Go. I can't seem to find anything documented anywhere on this. This is what I've tried so far:

func test() map {
// Get Auth Token (POST https://192.168.13.234/aperture/api/users/authorize)
anotherMap := map[string]string{"a": "b", "c": "d"}
return anotherMap
}

答案1

得分: 8

返回的映射类型必须完全定义。

游乐场:http://play.golang.org/p/26LFrBhpBC

func test() map[string]string {
	anotherMap := map[string]string{"a": "b", "c": "d"}
	return anotherMap
}
英文:

The return map type must be fully defined.

Playground: http://play.golang.org/p/26LFrBhpBC

func test() map[string]string {
	anotherMap := map[string]string{"a": "b", "c": "d"}
	return anotherMap
}

huangapple
  • 本文由 发表于 2014年12月16日 22:46:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/27507259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定