1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package data
- import (
- "strings"
- "time"
- "github.com/google/btree"
- "git.scraperwall.com/scw/grs"
- )
- type RequestData struct {
- ID string `bson:"_id,omitempty" json:"_id,omitempty"`
- Connection string `bson:"connection" json:"connection"`
- IpDst string `bson:"ip_dst" json:"ip_dst"`
- TcpSeq uint32 `bson:"tcp_seq" json:"tcp_seq"`
- XForwardedFor string `bson:"x_forwarded_for" json:"x_forwarded_for"`
- XRealIP string `bson:"x_real_ip" json:"x_real_ip"`
- Origin string `bson:"origin" json:"origin"`
- PortDst uint32 `bson:"port_dst" json:"port_dst"`
- Referer string `bson:"referer" json:"referer"`
- XRequestedWith string `bson:"x_requested_with" json:"x_requested_with"`
- PortSrc uint32 `bson:"port_src" json:"port_src"`
- Url string `bson:"url" json:"url"`
- Reverse string `bson:"reverse" json:"reverse"`
- AcceptEncoding string `bson:"accept_encoding" json:"accept_encoding"`
- AcceptLanguage string `bson:"accept_language" json:"accept_language"`
- CreatedAt time.Time `bson:"created_at" json:"created_at"`
- SortTime time.Time `bson:"-" bson:"-"`
- IpSrc string `bson:"ip_src" json:"ip_src"`
- Method string `bson:"method" json:"method"`
- UserAgent string `bson:"user_agent" json:"user_agent"`
- Accept string `bson:"accept" json:"accept"`
- Cookie string `bson:"cookie" json:"cookie"`
- Host string `bson:"host" json:"host"`
- Protocol string `bson:"protocol" json:"protocol"`
- Source string `bson:"source" json:"source"`
- Via string `bson:"via" json:"via"`
- DataRaw map[string]interface{} `bson:"data_raw" json:"data_raw"`
- Weight uint64 `bson:"weight" json:"weight"`
- Grs grs.GRS `bson:"grs" json:"grs"`
- }
- func (a *RequestData) Less(b btree.Item) bool {
- return a.CreatedAt.Before(b.(*RequestData).CreatedAt)
- }
- func (a *RequestData) ToRequest() *Request {
- return &Request{
- Url: a.Url,
- Reverse: a.Reverse,
- IpSrc: a.IpSrc,
- IpDst: a.IpDst,
- PortSrc: a.PortSrc,
- PortDst: a.PortDst,
- TcpSeq: a.TcpSeq,
- CreatedAt: a.CreatedAt.UnixNano(),
- XForwardedFor: a.XForwardedFor,
- XRealIP: a.XRealIP,
- Method: a.Method,
- Origin: a.Origin,
- Referer: a.Referer,
- UserAgent: a.UserAgent,
- Source: a.Source,
- Host: a.Host,
- Protocol: a.Protocol,
- Connection: a.Connection,
- XRequestedWith: a.XRequestedWith,
- AcceptEncoding: a.AcceptEncoding,
- AcceptLanguage: a.AcceptLanguage,
- Accept: a.Accept,
- Cookie: a.Cookie,
- Via: a.Via,
- }
- }
- // Path returns the Url without any query string
- func (a *RequestData) Path() string {
- idx := strings.Index(a.Url, "?")
- if idx >= 0 {
- return a.Url[0:idx]
- }
- return a.Url
- }
|