Repository navigation
Expand file tree
/
Copy pathctx.go
More file actions
75 lines (68 loc) · 1.76 KB
/
Copy pathctx.go
File metadata and controls
75 lines (68 loc) · 1.76 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
package gosl
import "context"
type InternalContext struct {
base context.Context
properites map[Gosl_Key]any
}
type Context struct {
Data any
Ctx context.Context
}
func Hijack(ctx context.Context) *InternalContext {
var base *InternalContext
if tmp, ok := ctx.Value(INTERNAL_CONTEXT).(*InternalContext); ok {
base = tmp
} else {
base = &InternalContext{
base: ctx,
properites: map[Gosl_Key]any{
SQL_KEY: ctx.Value(SQL_KEY),
CACHE_SQL_KEY: ctx.Value(CACHE_SQL_KEY),
CURRENT_SQL_KEY: ctx.Value(CURRENT_SQL_KEY),
PRIMARY_SQL_KEY: ctx.Value(SQL_KEY),
SYSTEM_STACK: ctx.Value(SYSTEM_STACK),
SYSTEM_CALLBACK_DEPTH: ctx.Value(SYSTEM_CALLBACK_DEPTH),
},
}
}
return base
}
func (i *InternalContext) Base() context.Context {
return i.base
}
func (i *InternalContext) Get(key any) any {
switch key {
case SQL_KEY:
return i.properites[SQL_KEY]
case CACHE_SQL_KEY:
return i.properites[CACHE_SQL_KEY]
case CURRENT_SQL_KEY:
return i.properites[CURRENT_SQL_KEY]
case PRIMARY_SQL_KEY:
return i.properites[PRIMARY_SQL_KEY]
case SYSTEM_STACK:
return i.properites[SYSTEM_STACK]
case SYSTEM_CALLBACK_DEPTH:
return i.properites[SYSTEM_CALLBACK_DEPTH]
}
return i.base.Value(key)
}
func (i *InternalContext) Set(key, value any) {
switch key {
case SQL_KEY:
i.properites[SQL_KEY] = value
case CACHE_SQL_KEY:
i.properites[CACHE_SQL_KEY] = value
case CURRENT_SQL_KEY:
i.properites[CURRENT_SQL_KEY] = value
case PRIMARY_SQL_KEY:
i.properites[PRIMARY_SQL_KEY] = value
case SYSTEM_STACK:
i.properites[SYSTEM_STACK] = value
case SYSTEM_CALLBACK_DEPTH:
i.properites[SYSTEM_CALLBACK_DEPTH] = value
}
}
func (i *InternalContext) NilProperties() bool {
return len(i.properites) == 0
}