-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathobjectmap.go
48 lines (39 loc) · 1007 Bytes
/
objectmap.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
47
48
package ken
// ObjectProvider specifies an instance providing
// objects by string key.
type ObjectProvider interface {
// Get returns a stored object by its
// key, if existent.
Get(key string) interface{}
}
// ObjectInjector specifies an instance which
// allows storing an object by string key.
type ObjectInjector interface {
// Set stores the given object by given
// key.
Set(key string, obj interface{})
}
// ObjectMap combines ObjectProvider and
// ObjectInjector.
type ObjectMap interface {
ObjectProvider
ObjectInjector
// Purge cleans all stored objects and
// keys from the provider.
Purge()
}
// simpleObjectMap implements ObjectMap for
// a map[string]interface{}.
type simpleObjectMap map[string]interface{}
var _ ObjectMap = (simpleObjectMap)(nil)
func (m simpleObjectMap) Get(key string) interface{} {
return m[key]
}
func (m simpleObjectMap) Set(key string, obj interface{}) {
m[key] = obj
}
func (m simpleObjectMap) Purge() {
for k := range m {
delete(m, k)
}
}