Go 语言中的 map 示例(key-value 键值对) :

package main

import "fmt"

type PersonInfo struct {
	ID      string
	Name    string
	Address string
}

func main() {
	var persionDB map[string]PersonInfo
	persionDB = make(map[string]PersonInfo)

	persionDB["1234"] = PersonInfo{"12345", "Tom", "Room 203,..."}
	persionDB["1"] = PersonInfo{"1", "Jack", "Room 101,..."}

	person, ok := persionDB["1234"]

	if ok {
		fmt.Println("Found person", person.Name, "with ID 1234.")
	} else {
		fmt.Println("Did not find person with ID 1234.")
	}
}