Ich suche Gorilla Kontext zum Quellcode. Ich verstehe nicht, was es synchronisiert, mutex.Lock, mutex.Unlock genau. Es läuft immer noch, wenn ich mutex.Lock und Mutex.Unlock aus Quellcodes entfernt habe.Was ist Sync (sync.RWMutex) in Golang
import (
"net/http"
"sync"
"time"
)
var (
mutex sync.RWMutex
data = make(map[*http.Request]map[interface{}]interface{})
datat = make(map[*http.Request]int64)
)
// Set stores a value for a given key in a given request.
func Set(r *http.Request, key, val interface{}) {
mutex.Lock()
if data[r] == nil {
data[r] = make(map[interface{}]interface{})
datat[r] = time.Now().Unix()
}
data[r][key] = val
mutex.Unlock()
}