/
action_context.go
62 lines (52 loc) · 1.29 KB
/
action_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package actions
import (
"github.com/iwind/TeaGo/maps"
"sync"
)
// ActionContext 上下文变量容器
type ActionContext struct {
context maps.Map
locker sync.RWMutex
}
// NewActionContext 获取新对象
func NewActionContext() *ActionContext {
return &ActionContext{
context: maps.Map{},
}
}
// Set 设置变量
func (this *ActionContext) Set(key string, value interface{}) {
this.locker.Lock()
defer this.locker.Unlock()
this.context[key] = value
}
// Get 获取变量
func (this *ActionContext) Get(key string) interface{} {
this.locker.RLock()
defer this.locker.RUnlock()
return this.context.Get(key)
}
// GetString 获取string变量
func (this *ActionContext) GetString(key string) string {
this.locker.RLock()
defer this.locker.RUnlock()
return this.context.GetString(key)
}
// GetInt 获取int变量
func (this *ActionContext) GetInt(key string) int {
this.locker.RLock()
defer this.locker.RUnlock()
return this.context.GetInt(key)
}
// GetInt64 获取int64变量
func (this *ActionContext) GetInt64(key string) int64 {
this.locker.RLock()
defer this.locker.RUnlock()
return this.context.GetInt64(key)
}
// GetBool 获取bool变量
func (this *ActionContext) GetBool(key string) bool {
this.locker.RLock()
defer this.locker.RUnlock()
return this.context.GetBool(key)
}