-
Notifications
You must be signed in to change notification settings - Fork 51
/
l7.go
122 lines (109 loc) · 2.3 KB
/
l7.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
package l7
import (
"strconv"
"time"
)
type Protocol uint8
const (
ProtocolHTTP Protocol = 1
ProtocolPostgres Protocol = 2
ProtocolRedis Protocol = 3
ProtocolMemcached Protocol = 4
ProtocolMysql Protocol = 5
ProtocolMongo Protocol = 6
ProtocolKafka Protocol = 7
ProtocolCassandra Protocol = 8
ProtocolRabbitmq Protocol = 9
ProtocolNats Protocol = 10
ProtocolHTTP2 Protocol = 11
ProtocolDubbo2 Protocol = 12
)
func (p Protocol) String() string {
switch p {
case ProtocolHTTP:
return "HTTP"
case ProtocolPostgres:
return "Postgres"
case ProtocolRedis:
return "Redis"
case ProtocolMemcached:
return "Memcached"
case ProtocolMysql:
return "Mysql"
case ProtocolMongo:
return "Mongo"
case ProtocolKafka:
return "Kafka"
case ProtocolCassandra:
return "Cassandra"
case ProtocolRabbitmq:
return "Rabbitmq"
case ProtocolNats:
return "NATS"
case ProtocolHTTP2:
return "HTTP2"
case ProtocolDubbo2:
return "Dubbo2"
}
return "UNKNOWN:" + strconv.Itoa(int(p))
}
type Method uint8
const (
MethodUnknown Method = 0
MethodProduce Method = 1
MethodConsume Method = 2
MethodStatementPrepare Method = 3
MethodStatementClose Method = 4
MethodHttp2ClientFrames Method = 5
MethodHttp2ServerFrames Method = 6
)
func (m Method) String() string {
switch m {
case MethodUnknown:
return "unknown"
case MethodProduce:
return "produce"
case MethodConsume:
return "consume"
case MethodStatementPrepare:
return "statement_prepare"
case MethodStatementClose:
return "statement_close"
case MethodHttp2ClientFrames:
return "http2_client_frames"
case MethodHttp2ServerFrames:
return "http2_server_frames"
}
return "UNKNOWN:" + strconv.Itoa(int(m))
}
type Status int
const (
StatusUnknown Status = 0
StatusOk Status = 200
StatusFailed Status = 500
)
func (s Status) String() string {
switch s {
case StatusUnknown:
return "unknown"
case StatusOk:
return "ok"
case StatusFailed:
return "failed"
}
return strconv.Itoa(int(s))
}
func (s Status) Http() string {
return strconv.Itoa(int(s))
}
func (s Status) Error() bool {
return s == StatusFailed
}
type RequestData struct {
Protocol Protocol
Status Status
Duration time.Duration
Method Method
StatementId uint32
Payload []byte
}