-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_statics.go
59 lines (52 loc) · 1.01 KB
/
api_statics.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
package main
import (
"net/http"
"sync/atomic"
"time"
)
// APIStatus shows the current api status.
type APIStatus struct {
TotalDuration time.Duration
MinRequestTime time.Duration
MaxRequestTime time.Duration
NumberOfRequests int
TotalResponseSize int64
AvgReqTime time.Duration
ErrorCount int
StatusCodes *StatusCodes
}
// StatusCodes stores http status codes
type StatusCodes struct {
OneXX int
TwoXX int
ThreeXX int
FourXX int
FiveXX int
Others int
}
func headerSize(headers http.Header) (result int64) {
result = 0
for k, v := range headers {
result += int64(len(k) + len(": \r\n"))
for _, s := range v {
result += int64(len(s))
}
}
result += int64(len("\r\n"))
return result
}
func findMaxRequestTime(t1, t2 time.Duration) time.Duration {
if t1 > t2 {
return t1
}
return t2
}
func findMinRequestTime(t1, t2 time.Duration) time.Duration {
if t1 < t2 {
return t1
}
return t2
}
func (conf *APIConfig) stop() {
atomic.StoreInt32(&conf.interrupt, 1)
}