forked from fwhezfwhez/errorx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
42 lines (37 loc) · 766 Bytes
/
context.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
package errorCollection
import "sync"
type Context struct {
M *sync.RWMutex
Map map[string]interface{}
}
func NewContext() *Context {
return &Context{
M: &sync.RWMutex{},
Map: make(map[string]interface{}, 0),
}
}
func (c *Context) Set(key string, value interface{}) {
c.M.Lock()
defer c.M.Unlock()
c.Map[key] = value
}
func (c *Context) Get(key string) interface{} {
c.M.RLock()
defer c.M.RUnlock()
return c.Map[key]
}
func (c *Context) GetString(key string) string {
c.M.RLock()
defer c.M.RUnlock()
return c.Map[key].(string)
}
func (c *Context) GetBool(key string) bool {
c.M.RLock()
defer c.M.RUnlock()
return c.Map[key].(bool)
}
func (c *Context) GetInt(key string) int {
c.M.RLock()
defer c.M.RUnlock()
return c.Map[key].(int)
}