forked from parkghost/gohttpbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
43 lines (36 loc) · 837 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
43
package main
import (
"sync"
)
type Context struct {
config *Config
start *sync.WaitGroup
stop chan struct{}
rwm *sync.RWMutex
store map[string]interface{}
}
func NewContext(config *Config) *Context {
start := &sync.WaitGroup{}
start.Add(config.concurrency)
return &Context{config, start, make(chan struct{}), &sync.RWMutex{}, make(map[string]interface{})}
}
func (c *Context) SetString(key string, value string) {
c.rwm.Lock()
defer c.rwm.Unlock()
c.store[key] = value
}
func (c *Context) GetString(key string) string {
c.rwm.RLock()
defer c.rwm.RUnlock()
return c.store[key].(string)
}
func (c *Context) SetInt(key string, value int) {
c.rwm.Lock()
defer c.rwm.Unlock()
c.store[key] = value
}
func (c *Context) GetInt(key string) int {
c.rwm.RLock()
defer c.rwm.RUnlock()
return c.store[key].(int)
}