github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/concurrent/go_below_19.go (about) 1 //+build !go1.9 2 3 package concurrent 4 5 import "sync" 6 7 type Map struct { 8 lock sync.RWMutex 9 data map[interface{}]interface{} 10 } 11 12 func NewMap() *Map { 13 return &Map{ 14 data: make(map[interface{}]interface{}, 32), 15 } 16 } 17 18 func (m *Map) Load(key interface{}) (elem interface{}, found bool) { 19 m.lock.RLock() 20 elem, found = m.data[key] 21 m.lock.RUnlock() 22 return 23 } 24 25 func (m *Map) Store(key interface{}, elem interface{}) { 26 m.lock.Lock() 27 m.data[key] = elem 28 m.lock.Unlock() 29 } 30