Fix the 'concurrent map read and map write' panic by wrapping all map access with a sync.Mutex or sync.RWMutex.
The error occurs because multiple goroutines are accessing the same map simultaneously without synchronization, with at least one performing a write. Protect the map with a sync.Mutex or sync.RWMutex to ensure only one goroutine accesses it at a time.
var mu sync.Mutex
var data = make(map[string]int)
// Write
mu.Lock()
data[key] = value
mu.Unlock()
// Read
mu.Lock()
val := data[key]
mu.Unlock()
The "fatal error: concurrent map read and map write" means two parts of your program tried to use the same data list simultaneously, with one changing it while the other read it. It's like two people writing on the same whiteboard at once, causing one to overwrite the other or crash the system. You need a traffic light (a mutex) to ensure only one person uses the board at a time.