This is a created article in which the information may have evolved or changed.
map structure, personal feel can and PHP is a kind of array, is a key-value hash structure. In go, key can be a type other than the Func,array,slice,map type
Simple to use:
m:=map[string]string{} m["key1"]="val1"
The map structure and slice are the same, and are a pointer. When assigning a value, copy the pointer to the new variable
Map additions and deletions to check the operation:
package mainimport "fmt"func main(){ m:=map[string]string{"key1":"value"} fmt.Println(m) m["key2"]="value2" fmt.Println(m) p:=m["key1"] fmt.Println(p) delete(m,"key1") fmt.Println(m)}
New and make differences
New (T) can be used to create a normal type, returning a pointer to the initialized T value.
Make (S) can only be used to create slice,map,channel. Returns an initialized s value (equivalent to a pointer).