-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstance.go
More file actions
71 lines (56 loc) · 1.32 KB
/
Copy pathinstance.go
File metadata and controls
71 lines (56 loc) · 1.32 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
package xmux
import (
"net/http"
)
const xmux_context = "XMUX_CONTEXT"
type FlowData struct {
Data any
// 处理后的数据
ctx map[string]interface{} // 用来传递自定义值
// mu *sync.RWMutex
Response interface{} // 返回的数据结构
connectId int64
funcName string
pages map[string]struct{}
StatusCode int
Body []byte
cacheKey string
module []func(w http.ResponseWriter, r *http.Request) bool
url string
}
func GetInstance(r *http.Request) *FlowData {
return r.Context().Value(xmux_context).(*FlowData)
}
func (data *FlowData) Set(k string, v interface{}) {
data.ctx[k] = v
}
func (data *FlowData) SetCacheKey(key string) {
data.cacheKey = key
}
func (data *FlowData) GetCacheKey() string {
return data.cacheKey
}
func (data *FlowData) GetConnectId() int64 {
return data.connectId
}
func (data *FlowData) GetFuncName() string {
return data.funcName
}
func (data *FlowData) GetUrl() string {
return data.url
}
func (data *FlowData) GetModules() []func(http.ResponseWriter, *http.Request) bool {
return data.module
}
func (data *FlowData) GetPageKeys() map[string]struct{} {
return data.pages
}
func (data *FlowData) Get(k string) interface{} {
if v, ok := data.ctx[k]; ok {
return v
}
return nil
}
func (data *FlowData) Del(k string) {
delete(data.ctx, k)
}