Documentation
¶
Index ¶
Constants ¶
const MaxItemsInResponse = 10000
MaxItemsInResponse is the maximum number of hashes that will be returned when asked for recent screenshots.
Variables ¶
var ( // ErrInvalidHash is the error when a hash string is invalid. ErrInvalidHash = errors.New("invalid hash string") // ErrUnsupportedHashMethod is the error when the requested hash method // is not supported. ErrUnsupportedHashMethod = errors.New("hash method unsupported") )
Functions ¶
func RecentScreenshotHashes ¶
func RecentScreenshotHashes( ds shared.Datastore, browser, browserVersion, os, osVersion string, limit *int, ) ([]string, error)
RecentScreenshotHashes gets the most recently used screenshot hash strings based on the given arguments.
We first try to find screenshots with all the four labels. When there are not enough, we remove the least important label and try again.
Types ¶
type Screenshot ¶
type Screenshot struct { HashDigest string HashMethod string Labels []string // These two fields can be left empty and will be filled by Store(). Counter int LastUsed time.Time }
Screenshot is the entity stored in Datastore for a known screenshot hash and its metadata.
func NewScreenshot ¶
func NewScreenshot(labels ...string) *Screenshot
NewScreenshot creates a new Screenshot with the given labels (empty labels are omitted).
func (*Screenshot) Hash ¶
func (s *Screenshot) Hash() string
Hash returns the "HASH_METHOD:HASH_DIGEST" representation of the screenshot used in the API.
func (*Screenshot) Key ¶
func (s *Screenshot) Key() string
Key returns the Datastore name key for this screenshot.
Note that the order of HashDigest and HashMethod is inversed for better key space distribution.
func (*Screenshot) SetHashFromFile ¶
func (s *Screenshot) SetHashFromFile(f io.Reader, hashMethod string) error
SetHashFromFile hashes a file and sets the HashMethod and HashDigest fields.
func (*Screenshot) Store ¶
func (s *Screenshot) Store(ds shared.Datastore) error
Store finalizes the struct and stores it to Datastore.
Before writing to Datastore, this function will first check if there is an existing record with the same key; if so, it updates the struct to include all existing Labels and sets Counter to existing Counter + 1. Note that this is NOT done in a transaction for better performance (both Labels and Counter are auxiliary information that is OK to lose in a race condition). Lastly, LastUsed is populated with the current timestamp.