-
Notifications
You must be signed in to change notification settings - Fork 2
/
request_call.go
43 lines (36 loc) · 1.02 KB
/
request_call.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 shared
import (
"github.com/iwind/TeaGo/maps"
"net/http"
)
// RequestCall 请求调用
type RequestCall struct {
Formatter func(source string) string // 当前变量格式化函数
Request *http.Request // 当前请求
Domain string // 当前域名
ResponseCallbacks []func(resp http.ResponseWriter)
Options maps.Map
}
// NewRequestCall 获取新对象
func NewRequestCall() *RequestCall {
return &RequestCall{
Options: maps.Map{},
}
}
// Reset 重置
func (this *RequestCall) Reset() {
this.Formatter = nil
this.Request = nil
this.ResponseCallbacks = nil
this.Options = maps.Map{}
}
// AddResponseCall 添加响应回调
func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter)) {
this.ResponseCallbacks = append(this.ResponseCallbacks, callback)
}
// CallResponseCallbacks 执行响应回调
func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter) {
for _, callback := range this.ResponseCallbacks {
callback(resp)
}
}