Created
August 11, 2019 00:33
-
-
Save ealipio/d85d9e91aa5269cef30817ab096f1246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type user struct { | |
name string | |
surname string | |
} | |
func main() { | |
//Declare and make a map that stores values | |
// of type user with a key of type string | |
users := make(map[string]user) | |
// add key/value pairs | |
users["Alipio"] = user{"Eisson", "Alipio"} | |
users["Ford"] = user{"Henry", "Ford"} | |
users["Mouse"] = user{"Mickey", "Mouse"} | |
users["Nikola"] = user{"Nikola", "Tesla"} | |
//fmt.Printf("users: %v", users) | |
// iterate over the map using value semantic give a copy | |
for key, value := range users { | |
fmt.Println(key, value) | |
} | |
fmt.Println() | |
// iterate over the map and notice the results are different | |
for key := range users { | |
fmt.Println(key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment