Maps

A map maps keys to values.

The zero value of a map is nil. A nil map has no keys, nor can keys be added.

The make function returns a map of the given type, initialized and ready for use.

maps.go

  1. package main
  2. import "fmt"
  3. type Vertex struct {
  4. Lat, Long float64
  5. }
  6. var m map[string]Vertex
  7. func main() {
  8. m = make(map[string]Vertex)
  9. m["Bell Labs"] = Vertex{
  10. 40.68433, -74.39967,
  11. }
  12. fmt.Println(m["Bell Labs"])
  13. }