diff --git a/dorkgen.go b/dorkgen.go index d2e5c44..03ae1c0 100644 --- a/dorkgen.go +++ b/dorkgen.go @@ -1,17 +1,15 @@ package dorkgen -// engineFactory is the main interface for +// EngineFactory is the main interface for // search engine implementations. -type engineFactory interface { - Site(string) *GoogleSearch - ToString() string - ToURL() string - Intext(string) *GoogleSearch - Inurl(string) *GoogleSearch - Filetype(string) *GoogleSearch - Cache(string) *GoogleSearch - Related(string) *GoogleSearch - Ext(string) *GoogleSearch - Exclude(string) *GoogleSearch - Group(string) *GoogleSearch +type EngineFactory struct { + tags []string +} + +func (e *EngineFactory) concat(tag string, value string, quotes bool) string { + if quotes { + return tag + "\"" + value + "\"" + } + + return tag + value } diff --git a/google.go b/google.go index 9264deb..d2d6b54 100644 --- a/google.go +++ b/google.go @@ -18,18 +18,9 @@ const ( intextTag = "intext:" ) -// GoogleSearch is the Google implementation for Dorkgen +// GoogleSearch is the Google search implementation for Dorkgen type GoogleSearch struct { - engineFactory - tags []string -} - -func concat(tag string, value string, quotes bool) string { - if quotes { - return tag + "\"" + value + "\"" - } - - return tag + value + EngineFactory } // ToString converts all tags to a single request @@ -53,8 +44,7 @@ func (e *GoogleSearch) ToURL() string { // Site specifically searches that particular site and lists all the results for that site. func (e *GoogleSearch) Site(site string) *GoogleSearch { - e.tags = append(e.tags, concat(siteTag, site, false)) - + e.tags = append(e.tags, e.concat(siteTag, site, false)) return e } @@ -66,43 +56,43 @@ func (e *GoogleSearch) Or() *GoogleSearch { // Intext searches for the occurrences of keywords all at once or one at a time. func (e *GoogleSearch) Intext(text string) *GoogleSearch { - e.tags = append(e.tags, concat(intextTag, text, true)) + e.tags = append(e.tags, e.concat(intextTag, text, true)) return e } // Inurl searches for a URL matching one of the keywords. func (e *GoogleSearch) Inurl(url string) *GoogleSearch { - e.tags = append(e.tags, concat(urlTag, url, true)) + e.tags = append(e.tags, e.concat(urlTag, url, true)) return e } // Filetype searches for a particular filetype mentioned in the query. func (e *GoogleSearch) Filetype(filetype string) *GoogleSearch { - e.tags = append(e.tags, concat(filetypeTag, filetype, true)) + e.tags = append(e.tags, e.concat(filetypeTag, filetype, true)) return e } // Cache shows the version of the web page that Google has in its cache. func (e *GoogleSearch) Cache(url string) *GoogleSearch { - e.tags = append(e.tags, concat(cacheTag, url, true)) + e.tags = append(e.tags, e.concat(cacheTag, url, true)) return e } // Related list web pages that are “similar” to a specified web page. func (e *GoogleSearch) Related(url string) *GoogleSearch { - e.tags = append(e.tags, concat(relatedTag, url, true)) + e.tags = append(e.tags, e.concat(relatedTag, url, true)) return e } // Ext searches for a particular file extension mentioned in the query. func (e *GoogleSearch) Ext(ext string) *GoogleSearch { - e.tags = append(e.tags, concat(extTag, ext, false)) + e.tags = append(e.tags, e.concat(extTag, ext, false)) return e } // Exclude excludes some results. func (e *GoogleSearch) Exclude(value string) *GoogleSearch { - e.tags = append(e.tags, concat(excludeTag, value, false)) + e.tags = append(e.tags, e.concat(excludeTag, value, false)) return e } @@ -114,6 +104,6 @@ func (e *GoogleSearch) Group(value string) *GoogleSearch { // Intitle searches for occurrences of keywords in title all or one. func (e *GoogleSearch) Intitle(value string) *GoogleSearch { - e.tags = append(e.tags, concat(intitleTag, value, true)) + e.tags = append(e.tags, e.concat(intitleTag, value, true)) return e }