Go learning notes map (Dictionary)


1. Declaration assignment:

var m1 map[string]int
m1 = map[string]int{"name":1, "xxx":2}
be equal to
m1 := make(map[string]int)
be equal to
m1 := map[string]int{}
//m2 := map[string]interface{}{}

2. Map is a reference type

m2 := m1
m2["age"] = 18
//Results of M1: Map[ age:18 name 1 xxx:2 ]

3. Determine whether the map value exists

  • OK, it’s bool
    _, ok := map1[key1]
    //Or with if
    if _, ok := map1[key1]; ok {


    Delete (map, key1) // if key1 does not exist, the operation will not generate an error.

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint

Recommended Today

The actor model is so excellent under distributed high concurrency

Write at the beginning In general, there are two strategies for communicating in concurrent threads: shared data and messaging. One of the biggest problems of concurrent programming with shared data is data condition competition. It’s a headache to deal with all kinds of locks. Most of the traditional popular language concurrency is based on shared […]