request_data.go 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package data
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/google/btree"
  6. "git.scraperwall.com/scw/grs"
  7. )
  8. type RequestData struct {
  9. ID string `bson:"_id,omitempty" json:"_id,omitempty" form:"_id,omitempty"`
  10. Connection string `bson:"connection" json:"connection" form:"connection,omitempty"`
  11. IpDst string `bson:"ip_dst" json:"ip_dst" form:"ip_dst,omitempty"`
  12. TcpSeq uint32 `bson:"tcp_seq" json:"tcp_seq" form:"tcp_seq,omitempty"`
  13. XForwardedFor string `bson:"x_forwarded_for" json:"x_forwarded_for,omitempty" form:"x_forwarded_for,omitempty"`
  14. XRealIP string `bson:"x_real_ip" json:"x_real_ip,omitempty" form:"x_real_ip,omitempty"`
  15. Origin string `bson:"origin" json:"origin,omitempty" form:"origin,omitempty"`
  16. PortDst uint32 `bson:"port_dst" json:"port_dst,omitempty" form: "port_dst,omitempty"`
  17. Referer string `bson:"referer" json:"referer,omitempty" form:"referer,omitempty"`
  18. XRequestedWith string `bson:"x_requested_with" json:"x_requested_with,omitempty" form:"x_requested_with.omitempty"`
  19. PortSrc uint32 `bson:"port_src" json:"port_src,omitempty" form:"port_src,omitempty"`
  20. Url string `bson:"url" json:"url,omitempty" form:"url,omitempty"`
  21. Reverse string `bson:"reverse" json:"reverse,omitempty" form:"reverse,omitempty"`
  22. AcceptEncoding string `bson:"accept_encoding" json:"accept_encoding,omitempty" form:"accept_encoding,omitempty"`
  23. AcceptLanguage string `bson:"accept_language" json:"accept_language,omitempty" form:"accept_language,omitempty"`
  24. CreatedAt time.Time `bson:"created_at" json:"created_at,omitempty" form:"created_at,omitempty"`
  25. SortTime time.Time `bson:"-" json:"-" form"-"`
  26. IpSrc string `bson:"ip_src" json:"ip_src,omitempty" form:"ip_src,omitempty"`
  27. Method string `bson:"method" json:"method,omitempty" form:"method,omitempty"`
  28. UserAgent string `bson:"user_agent" json:"user_agent,omitempty" form:"user_agent,omitempty"`
  29. Accept string `bson:"accept" json:"accept,omitempty" form:"accept,omitempty"`
  30. Cookie string `bson:"cookie" json:"cookie,omitempty" form:"cookie,omitempty"`
  31. Host string `bson:"host" json:"host,omitempty" form:"host,omitempty"`
  32. HostName string `bson:"hostname" json:"hostname,omitempty" form:"hostname,omitempty"`
  33. Protocol string `bson:"protocol" json:"protocol,omitempty" form:"protocol,omitempty"`
  34. Source string `bson:"source" json:"source,omitempty" form:"source,omitempty"`
  35. Via string `bson:"via" json:"via,omitempty" form:"via,omitempty"`
  36. Customer string `bson:"customer" json:"customer,omitempty" form:"customer,omitempty"`
  37. DataRaw map[string]interface{} `bson:"data_raw" json:"data_raw,omitempty" form:"data_raw,omitempty"`
  38. Weight uint64 `bson:"weight" json:"weight,omitempty" form:"weight,omitempty"`
  39. Grs grs.GRS `bson:"grs" json:"grs,omitempty" form:"grs,omitempty"`
  40. }
  41. func (a *RequestData) Less(b btree.Item) bool {
  42. return a.CreatedAt.Before(b.(*RequestData).CreatedAt)
  43. }
  44. func (a *RequestData) ToRequest() *Request {
  45. return &Request{
  46. Url: a.Url,
  47. Reverse: a.Reverse,
  48. IpSrc: a.IpSrc,
  49. IpDst: a.IpDst,
  50. PortSrc: a.PortSrc,
  51. PortDst: a.PortDst,
  52. TcpSeq: a.TcpSeq,
  53. CreatedAt: a.CreatedAt.UnixNano(),
  54. XForwardedFor: a.XForwardedFor,
  55. XRealIP: a.XRealIP,
  56. Method: a.Method,
  57. Origin: a.Origin,
  58. Referer: a.Referer,
  59. UserAgent: a.UserAgent,
  60. Source: a.Source,
  61. Host: a.Host,
  62. Protocol: a.Protocol,
  63. Connection: a.Connection,
  64. XRequestedWith: a.XRequestedWith,
  65. AcceptEncoding: a.AcceptEncoding,
  66. AcceptLanguage: a.AcceptLanguage,
  67. Accept: a.Accept,
  68. Cookie: a.Cookie,
  69. Via: a.Via,
  70. Customer: a.Customer,
  71. }
  72. }
  73. // Path returns the Url without any query string
  74. func (a *RequestData) Path() string {
  75. idx := strings.Index(a.Url, "?")
  76. if idx >= 0 {
  77. return a.Url[0:idx]
  78. }
  79. return a.Url
  80. }