Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning maps data structures

Tags:

dictionary

go

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
}
like image 699
user1513388 Avatar asked Jan 23 '26 04:01

user1513388


1 Answers

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
}
like image 149
siritinga Avatar answered Jan 26 '26 00:01

siritinga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!