Documentation
¶
Index ¶
- Constants
- type Controller
- func (c *Controller) Close() (err error)
- func (c *Controller) Delete(ctx context.Context, entryID string) (removed *Entry, err error)
- func (c *Controller) ForEach(fn func(*Entry) error, opts *mojura.IteratingOpts) (err error)
- func (c *Controller) Get(entryID string) (entry *Entry, err error)
- func (c *Controller) GetByIP(ipAddress string) (es []*Entry, err error)
- func (c *Controller) GetByUser(userID string) (es []*Entry, err error)
- func (c *Controller) GetByUserAgent(userAgent string) (es []*Entry, err error)
- func (c *Controller) GetDuplicates() (dups map[string]stringset.Map, err error)
- func (c *Controller) GetMatches(i Identifiers) (es []*Entry, err error)
- func (c *Controller) New(ctx context.Context, userID string, i Identifiers) (err error)
- func (c *Controller) NewFromHTTPRequst(ctx context.Context, userID string, req *http.Request) (err error)
- type Entry
- type Hash
- type Identifiers
Examples ¶
Constants ¶
const ( RelationshipUsers = "users" RelationshipIPAddresses = "ipAddresses" RelationshipUserAgents = "userAgents" RelationshipAcceptLanguages = "acceptLanguages" RelationshipSignatures = "signatures" )
Relationship key const block
const ( // ErrEmptyUserID is returned when the User ID for an Entry is empty ErrEmptyUserID = errors.Error("invalid user ID, cannot be empty") // ErrEmptyIPAddress is returned when the IP address for an Entry is empty ErrEmptyIPAddress = errors.Error("invalid IP address, cannot be empty") // ErrEmptyUserAgent is returned when the User Agent for an Entry is empty ErrEmptyUserAgent = errors.Error("invalid user agent, cannot be empty") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller represents a management layer to facilitate the retrieval and modification of Entries
func New ¶
func New(dir string) (cc *Controller, err error)
New will return a new instance of the Controller
Example ¶
var err error
if testController, err = New("./data"); err != nil {
log.Fatal(err)
}
func (*Controller) Close ¶
func (c *Controller) Close() (err error)
Close will close the controller and it's underlying dependencies
func (*Controller) ForEach ¶
func (c *Controller) ForEach(fn func(*Entry) error, opts *mojura.IteratingOpts) (err error)
ForEach will iterate through all Entries Note: The error constant mojura.Break can returned by the iterating func to end the iteration early
func (*Controller) Get ¶
func (c *Controller) Get(entryID string) (entry *Entry, err error)
Get will retrieve an Entry which has the same ID as the provided entryID
func (*Controller) GetByIP ¶
func (c *Controller) GetByIP(ipAddress string) (es []*Entry, err error)
GetByIP will retrieve all Entries associated with given IP address
Example ¶
var (
es []*Entry
err error
)
if es, err = testController.GetByIP("[IP Address]"); err != nil {
log.Fatal(err)
}
fmt.Println("Matching entries", es)
func (*Controller) GetByUser ¶
func (c *Controller) GetByUser(userID string) (es []*Entry, err error)
GetByUser will retrieve all Entries associated with given user
func (*Controller) GetByUserAgent ¶
func (c *Controller) GetByUserAgent(userAgent string) (es []*Entry, err error)
GetByUserAgent will retrieve all Entries associated with given user agent
Example ¶
var (
es []*Entry
err error
)
if es, err = testController.GetByUserAgent("[User Agent]"); err != nil {
log.Fatal(err)
}
fmt.Println("Matching entries", es)
func (*Controller) GetDuplicates ¶
func (c *Controller) GetDuplicates() (dups map[string]stringset.Map, err error)
GetDuplicates will get all exact signature duplicates
Example ¶
var (
dups map[string]stringset.Map
err error
)
if dups, err = testController.GetDuplicates(); err != nil {
log.Fatal(err)
}
fmt.Println("Duplicates", dups)
func (*Controller) GetMatches ¶
func (c *Controller) GetMatches(i Identifiers) (es []*Entry, err error)
GetMatches will retrieve all Entries associated with given user agent and ip pair
Example ¶
var (
i Identifiers
es []*Entry
err error
)
i.IPAddress = "64.233.191.255"
i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"
if es, err = testController.GetMatches(i); err != nil {
log.Fatal(err)
}
fmt.Println("Matching entries", es)
Example (Ip_only) ¶
var (
i Identifiers
es []*Entry
err error
)
i.IPAddress = "64.233.191.255"
if es, err = testController.GetMatches(i); err != nil {
log.Fatal(err)
}
fmt.Println("Matching entries", es)
Example (User_agent_only) ¶
var (
i Identifiers
es []*Entry
err error
)
i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
if es, err = testController.GetMatches(i); err != nil {
log.Fatal(err)
}
fmt.Println("Matching entries", es)
func (*Controller) New ¶
func (c *Controller) New(ctx context.Context, userID string, i Identifiers) (err error)
New will insert a new Entry to the back-end
Example ¶
var (
i Identifiers
err error
)
i.IPAddress = "64.233.191.255"
i.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36"
i.AcceptLanguage = "en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7"
if err = testController.New(context.Background(), "user_0", i); err != nil {
log.Fatal(err)
}
func (*Controller) NewFromHTTPRequst ¶
func (c *Controller) NewFromHTTPRequst(ctx context.Context, userID string, req *http.Request) (err error)
NewFromHTTPRequst will create and insert a new entry from a given http request
type Entry ¶
type Entry struct {
// Include mojura.Entry to auto-populate fields/methods needed to match the
mojura.Entry
// UserID which Entry is related to
UserID string `json:"userID"`
// Include identifiers
Identifiers
}
Entry represents a stored entry within the Controller
func (*Entry) GetRelationships ¶
func (e *Entry) GetRelationships() (r mojura.Relationships)
GetRelationships will return the relationship IDs associated with the Entry
type Hash ¶
type Hash [32]byte
Hash represents a hashed value
type Identifiers ¶
type Identifiers struct {
// IPAddress is the IP address of the user
IPAddress string `json:"ipAddress"`
// UserAgent is the user agent of the user
UserAgent string `json:"userAgent"`
// AcceptLanguage is the acceptLanguage value for the user
AcceptLanguage string `json:"acceptLanguage"`
}
Identifiers are the identifiers used for fingerprinting