Re:A quick and easy way to setup a RESTful JSON API in Go
by hierro on Saturday April 26, 2014 @11:11AM
(#7651622)
You're right, the example does have a glaring bug - and I completely agree with you, examples should not include incorrect code.
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).
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).