forked from timescale/tsbs
/
http.go
80 lines (69 loc) · 1.84 KB
/
http.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
package query
import (
"fmt"
"sync"
)
// HTTP encodes an HTTP request. This will typically by serialized for use
// by the appropriate tsbs_run_queries program.
type HTTP struct {
HumanLabel []byte
HumanDescription []byte
Method []byte
Path []byte
Body []byte
RawQuery []byte
StartTimestamp int64
EndTimestamp int64
id uint64
}
// HTTPPool is a sync.Pool of HTTP Query types
var HTTPPool = sync.Pool{
New: func() interface{} {
return &HTTP{
HumanLabel: []byte{},
HumanDescription: []byte{},
Method: []byte{},
Path: []byte{},
Body: []byte{},
RawQuery: []byte{},
StartTimestamp: 0,
EndTimestamp: 0,
}
},
}
// NewHTTP returns a new HTTP type Query
func NewHTTP() *HTTP {
return HTTPPool.Get().(*HTTP)
}
// GetID returns the ID of this Query
func (q *HTTP) GetID() uint64 {
return q.id
}
// SetID sets the ID for this Query
func (q *HTTP) SetID(n uint64) {
q.id = n
}
// String produces a debug-ready description of a Query.
func (q *HTTP) String() string {
return fmt.Sprintf("HumanLabel: \"%s\", HumanDescription: \"%s\", Method: \"%s\", Path: \"%s\", Body: \"%s\"", q.HumanLabel, q.HumanDescription, q.Method, q.Path, q.Body)
}
// HumanLabelName returns the human readable name of this Query
func (q *HTTP) HumanLabelName() []byte {
return q.HumanLabel
}
// HumanDescriptionName returns the human readable description of this Query
func (q *HTTP) HumanDescriptionName() []byte {
return q.HumanDescription
}
// Release resets and returns this Query to its pool
func (q *HTTP) Release() {
q.HumanLabel = q.HumanLabel[:0]
q.HumanDescription = q.HumanDescription[:0]
q.id = 0
q.Method = q.Method[:0]
q.Path = q.Path[:0]
q.Body = q.Body[:0]
q.StartTimestamp = 0
q.EndTimestamp = 0
HTTPPool.Put(q)
}