-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
47 lines (36 loc) · 722 Bytes
/
context.go
File metadata and controls
47 lines (36 loc) · 722 Bytes
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
package ramix
import "sync"
type Context struct {
Connection Connection
Request *Request
handlers []Handler
step int
keys map[string]any
lock sync.RWMutex
}
func (c *Context) Next() {
c.step++
for ; c.step < len(c.handlers); c.step++ {
c.handlers[c.step](c)
}
}
func (c *Context) Set(key string, value any) {
c.lock.Lock()
defer c.lock.Unlock()
if c.keys == nil {
c.keys = make(map[string]any)
}
c.keys[key] = value
}
func (c *Context) Get(key string) any {
c.lock.RLock()
defer c.lock.RUnlock()
return c.keys[key]
}
func newContext(connection Connection, request *Request) *Context {
return &Context{
Connection: connection,
Request: request,
step: -1,
}
}