Skip to content

Instantly share code, notes, and snippets.

@ealipio
Created August 11, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealipio/d85d9e91aa5269cef30817ab096f1246 to your computer and use it in GitHub Desktop.
Save ealipio/d85d9e91aa5269cef30817ab096f1246 to your computer and use it in GitHub Desktop.
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