-
Notifications
You must be signed in to change notification settings - Fork 0
/
har.go
181 lines (156 loc) · 4.7 KB
/
har.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package har
import (
"encoding/json"
"os"
"time"
)
// ParseHarFile 解析HAR格式的文件
func ParseHarFile(harFilePath string) (*Har, error) {
harFileBytes, err := os.ReadFile(harFilePath)
if err != nil {
return nil, err
}
har := new(Har)
err = json.Unmarshal(harFileBytes, har)
if err != nil {
return nil, err
}
return har, nil
}
// ParseHar 解析HAR格式的文件
func ParseHar(harFileBytes []byte) (*Har, error) {
har := new(Har)
err := json.Unmarshal(harFileBytes, har)
if err != nil {
return nil, err
}
return har, nil
}
// ------------------------------------------------- --------------------------------------------------------------------
type Har struct {
Log Log `json:"log"`
}
type Creator struct {
Name string `json:"name"`
Version string `json:"version"`
}
type PageTimings struct {
OnContentLoad float64 `json:"onContentLoad"`
OnLoad float64 `json:"onLoad"`
Comment string `json:"comment"`
}
type Pages struct {
StartedDateTime time.Time `json:"startedDateTime"`
ID string `json:"id"`
Title string `json:"title"`
PageTimings PageTimings `json:"pageTimings"`
}
type Headers struct {
Name string `json:"name"`
Value string `json:"value"`
}
type Request struct {
Method string `json:"method"`
URL string `json:"url"`
HTTPVersion string `json:"httpVersion"`
Cookies []Cookie `json:"cookies"`
Headers []Headers `json:"headers"`
QueryString []any `json:"queryString"`
HeadersSize int `json:"headersSize"`
BodySize int `json:"bodySize"`
}
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Path string `json:"path"`
Domain string `json:"domain"`
Expires time.Time `json:"expires"`
HTTPOnly bool `json:"httpOnly"`
Secure bool `json:"secure"`
SameSite string `json:"sameSite"`
}
type Content struct {
Size int `json:"size"`
MimeType string `json:"mimeType"`
}
type Response struct {
Status int `json:"status"`
StatusText string `json:"statusText"`
HTTPVersion string `json:"httpVersion"`
Cookies []Cookie `json:"cookies"`
Headers []Headers `json:"headers"`
RedirectURL string `json:"redirectURL"`
HeadersSize int `json:"headersSize"`
BodySize int `json:"bodySize"`
Content Content `json:"content"`
TransferSize int `json:"_transferSize"`
Error any `json:"_error"`
}
type BeforeRequest struct {
}
type AfterRequest struct {
}
type Cache struct {
BeforeRequest BeforeRequest `json:"beforeRequest"`
AfterRequest AfterRequest `json:"afterRequest"`
Comment string `json:"comment"`
}
type Timings struct {
Blocked float64 `json:"blocked"`
DNS float64 `json:"dns"`
Connect float64 `json:"connect"`
Send float64 `json:"send"`
Wait float64 `json:"wait"`
Receive float64 `json:"receive"`
Ssl float64 `json:"ssl"`
BlockedQueueing float64 `json:"_blocked_queueing"`
BlockedProxy float64 `json:"_blocked_proxy"`
}
type Entries struct {
StartedDateTime time.Time `json:"startedDateTime"`
Time float64 `json:"time"`
Request Request `json:"request"`
Response Response `json:"response"`
Cache Cache `json:"cache"`
Timings Timings `json:"timings"`
Pageref string `json:"pageref"`
Initiator Initiator `json:"_initiator"`
Priority string `json:"_priority"`
ResourceType string `json:"_resourceType"`
Connection string `json:"connection"`
ServerIPAddress string `json:"serverIPAddress"`
}
type Initiator struct {
Type string `json:"type"`
URL string `json:"url"`
LineNumber int `json:"lineNumber"`
Stack Stack `json:"stack"`
}
type Stack struct {
CallFrames []CallFrame `json:"callFrames"`
Parent Parent `json:"parent"`
}
type Parent struct {
Parent *Parent `json:"parent"`
Description string `json:"description"`
CallFrames []CallFrame `json:"callFrames"`
ParentID ParentID `json:"parentId"`
}
type ParentID struct {
ID string `json:"id"`
DebuggerID string `json:"debuggerId"`
}
type CallFrame struct {
FunctionName string `json:"functionName"`
ScriptID string `json:"scriptId"`
URL string `json:"url"`
LineNumber int `json:"lineNumber"`
ColumnNumber int `json:"columnNumber"`
}
type Log struct {
Version string `json:"version"`
Creator Creator `json:"creator"`
Pages []Pages `json:"pages"`
Entries []Entries `json:"entries"`
}
// ------------------------------------------------- --------------------------------------------------------------------