-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
map.go
46 lines (35 loc) · 799 Bytes
/
map.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2021 Clivern. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package util
import (
"sync"
)
// Map type
type Map struct {
sync.RWMutex
items map[string]interface{}
}
// NewMap creates a new instance of Map
func NewMap() Map {
return Map{items: make(map[string]interface{})}
}
// Get a key from a concurrent map
func (cm *Map) Get(key string) (interface{}, bool) {
cm.Lock()
defer cm.Unlock()
value, ok := cm.items[key]
return value, ok
}
// Set a key in a concurrent map
func (cm *Map) Set(key string, value interface{}) {
cm.Lock()
defer cm.Unlock()
cm.items[key] = value
}
// Delete deletes a key
func (cm *Map) Delete(key string) {
cm.Lock()
defer cm.Unlock()
delete(cm.items, key)
}