request_data.go 5.4 KB

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