Skip to content

add filtering#21

Merged
zellyn merged 1 commit into
browserutils:masterfrom
srlehn:filter
Oct 14, 2020
Merged

add filtering#21
zellyn merged 1 commit into
browserutils:masterfrom
srlehn:filter

Conversation

@srlehn
Copy link
Copy Markdown
Collaborator

@srlehn srlehn commented Oct 14, 2020

preparation for a signature change of the ReadCookie() funcs:

// currently:
func ReadSafariCookies(filename string, domainFilter string, nameFilter string, expireAfter time.Time) ([]*kooky.Cookie, error)
func ReadChromeCookies(filename string, domainFilter string, nameFilter string, expireAfter time.Time) ([]*kooky.Cookie, error)
func ReadFirefoxCookies(filename string) ([]*kooky.Cookie, error)

// planned:
ReadCookies(filename string, ...Filter) ([]*Cookie, error)

// example usage:
cookies, err := ReadCookies(filename) // default without filters
cookies, err := ReadCookies(filename, Domain(domainFilter), Name(nameFilter), ExpiresAfter(expireAfter)) // with filters
var ownFilter Filter = func(*Cookie) bool { /* do something */ }
cookies, err := ReadCookies(filename, ValueContais(valuePart), ownFilter, Debug, HTTPOnly) // with filters

change of the Read...() functions remains.


https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

@zellyn
Copy link
Copy Markdown
Collaborator

zellyn commented Oct 14, 2020

I understand adding arbitrary filters, but how does this remove the need for telling it which browser you want to read from?

@srlehn
Copy link
Copy Markdown
Collaborator Author

srlehn commented Oct 14, 2020

ah.... it doesn't. I had the separation from #14 in mind. then they are in firefox/chrome/... packages.

And i have something planned with a global search after locating the cookie dbs. I have some location code lying around which I have to prepare a bit. I was thinking a bit about the interface and structure but don't have much yet.

Here are some things I would like to add later:

type CookiesFile struct {
	Browser, Profile, Path string
}

type Reader interface {
	Read(*CookiesFile, ...Filter) ([]*Cookie, error)
}

type Searcher interface {
	Search(browser, profile string) ([]*CookiesFile, error)
}

@zellyn
Copy link
Copy Markdown
Collaborator

zellyn commented Oct 14, 2020

Ah, ok. Makes sense.

@zellyn zellyn merged commit 48b8668 into browserutils:master Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants