This is a creation in Article, where the information may have evolved or changed. For Jane's map such as map[string] string is still very well mastered.
The following procedure demonstrates a complex map
Package Main
Import "FMT"
Type PersonInfo struct {
ID string
Name string
Address string
}
Func Main () {
PERSONDB: = Make (Map[string][2]personinfo)
Initialize, note the initialization of the array
persondb["test1"] = [2]personinfo{{"12345", "Tom", "AAA"}, {"12346", "Xym", "BBB"}}
Element lookup, which is a common use method
V, OK: = persondb["Test1"]
If!ok {
Fmt. PRINTLN ("No Information Found")
Return
}
Print out all values and each score
Fmt. Printf ("V=%v v[0]=%v v[1]=%v \ n", V, V[0], v[1])
Use range to get the value easily
For I, V: = Range v {
Fmt. Println (i, V, v.id, v.address, V.name)
can do other processing.
}
}
Output Result:
v=[{12345 Tom AAA} {12346 Xym bbb}] v[0]={12345 Tom AAA} v[1]={12346 Xym BBB}
0 {12345 Tom AAA} 12345 AAA Tom
1 {12346 Xym bbb} 12346 BBB Xym