|
|
|
|
|
by lazyjones
4443 days ago
|
|
The "Countries" example does not look correct to me. Go maps aren't safe for concurrent use (such as parallel REST API requests in this case) and need to be protected with a sync.RWMutex or similar, although it might work safely in some special cases (I'm not sure). |
|
Just to clarify, maps can be read concurrently without locking as long as you're not writing to them. As soon as any concurrent operation might make changes to the map (as the example does) you need locking, preferably a sync.RWMutex (a sync.Mutex will also work but will be way less efficient for no good reason).