forked from hyper0x/goc2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
70 lines (56 loc) · 1.38 KB
/
data.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
63
64
65
66
67
68
69
70
package base
import (
"net/http"
)
// 数据的接口。
type Data interface {
Valid() bool // 数据是否有效。
}
// 请求。
type Request struct {
httpReq *http.Request // HTTP请求的指针值。
depth uint32 // 请求的深度。
}
// 创建新的请求。
func NewRequest(httpReq *http.Request, depth uint32) *Request {
return &Request{httpReq: httpReq, depth: depth}
}
// 获取HTTP请求。
func (req *Request) HttpReq() *http.Request {
return req.httpReq
}
// 获取深度值。
func (req *Request) Depth() uint32 {
return req.depth
}
// 数据是否有效。
func (req *Request) Valid() bool {
return req.httpReq != nil && req.httpReq.URL != nil
}
// 响应。
type Response struct {
httpResp *http.Response
depth uint32
}
// 创建新的响应。
func NewResponse(httpResp *http.Response, depth uint32) *Response {
return &Response{httpResp: httpResp, depth: depth}
}
// 获取HTTP响应。
func (resp *Response) HttpResp() *http.Response {
return resp.httpResp
}
// 获取深度值。
func (resp *Response) Depth() uint32 {
return resp.depth
}
// 数据是否有效。
func (resp *Response) Valid() bool {
return resp.httpResp != nil && resp.httpResp.Body != nil
}
// 条目。
type Item map[string]interface{}
// 数据是否有效。
func (item Item) Valid() bool {
return item != nil
}