英文:
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
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论