l7.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package l7
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. type Protocol uint8
  7. const (
  8. ProtocolHTTP Protocol = 1
  9. ProtocolPostgres Protocol = 2
  10. ProtocolRedis Protocol = 3
  11. ProtocolMemcached Protocol = 4
  12. ProtocolMysql Protocol = 5
  13. ProtocolMongo Protocol = 6
  14. ProtocolKafka Protocol = 7
  15. ProtocolCassandra Protocol = 8
  16. ProtocolRabbitmq Protocol = 9
  17. ProtocolNats Protocol = 10
  18. ProtocolHTTP2 Protocol = 11
  19. )
  20. func (p Protocol) String() string {
  21. switch p {
  22. case ProtocolHTTP:
  23. return "HTTP"
  24. case ProtocolPostgres:
  25. return "Postgres"
  26. case ProtocolRedis:
  27. return "Redis"
  28. case ProtocolMemcached:
  29. return "Memcached"
  30. case ProtocolMysql:
  31. return "Mysql"
  32. case ProtocolMongo:
  33. return "Mongo"
  34. case ProtocolKafka:
  35. return "Kafka"
  36. case ProtocolCassandra:
  37. return "Cassandra"
  38. case ProtocolRabbitmq:
  39. return "Rabbitmq"
  40. case ProtocolNats:
  41. return "NATS"
  42. case ProtocolHTTP2:
  43. return "HTTP2"
  44. }
  45. return "UNKNOWN:" + strconv.Itoa(int(p))
  46. }
  47. type Method uint8
  48. const (
  49. MethodUnknown Method = 0
  50. MethodProduce Method = 1
  51. MethodConsume Method = 2
  52. MethodStatementPrepare Method = 3
  53. MethodStatementClose Method = 4
  54. MethodHttp2ClientFrames Method = 5
  55. MethodHttp2ServerFrames Method = 6
  56. )
  57. func (m Method) String() string {
  58. switch m {
  59. case MethodUnknown:
  60. return "unknown"
  61. case MethodProduce:
  62. return "produce"
  63. case MethodConsume:
  64. return "consume"
  65. case MethodStatementPrepare:
  66. return "statement_prepare"
  67. case MethodStatementClose:
  68. return "statement_close"
  69. case MethodHttp2ClientFrames:
  70. return "http2_client_frames"
  71. case MethodHttp2ServerFrames:
  72. return "http2_server_frames"
  73. }
  74. return "UNKNOWN:" + strconv.Itoa(int(m))
  75. }
  76. type Status int
  77. const (
  78. StatusUnknown Status = 0
  79. StatusOk Status = 200
  80. StatusFailed Status = 500
  81. )
  82. func (s Status) String() string {
  83. switch s {
  84. case StatusUnknown:
  85. return "unknown"
  86. case StatusOk:
  87. return "ok"
  88. case StatusFailed:
  89. return "failed"
  90. }
  91. return strconv.Itoa(int(s))
  92. }
  93. func (s Status) Http() string {
  94. return strconv.Itoa(int(s))
  95. }
  96. func (s Status) Error() bool {
  97. return s == StatusFailed
  98. }
  99. type RequestData struct {
  100. Protocol Protocol
  101. Status Status
  102. Duration time.Duration
  103. Method Method
  104. StatementId uint32
  105. Payload []byte
  106. }