commit
9ae2785339
|
@ -14,3 +14,4 @@
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.idea
|
||||||
|
|
24
dorkgen.go
24
dorkgen.go
|
@ -1,17 +1,15 @@
|
||||||
package dorkgen
|
package dorkgen
|
||||||
|
|
||||||
// engineFactory is the main interface for
|
// EngineFactory is the main interface for
|
||||||
// search engine implementations.
|
// search engine implementations.
|
||||||
type engineFactory interface {
|
type EngineFactory struct {
|
||||||
Site(string) *GoogleSearch
|
tags []string
|
||||||
ToString() string
|
}
|
||||||
ToURL() string
|
|
||||||
Intext(string) *GoogleSearch
|
func (e *EngineFactory) concat(tag string, value string, quotes bool) string {
|
||||||
Inurl(string) *GoogleSearch
|
if quotes {
|
||||||
Filetype(string) *GoogleSearch
|
return tag + "\"" + value + "\""
|
||||||
Cache(string) *GoogleSearch
|
}
|
||||||
Related(string) *GoogleSearch
|
|
||||||
Ext(string) *GoogleSearch
|
return tag + value
|
||||||
Exclude(string) *GoogleSearch
|
|
||||||
Group(string) *GoogleSearch
|
|
||||||
}
|
}
|
||||||
|
|
32
google.go
32
google.go
|
@ -18,18 +18,9 @@ const (
|
||||||
intextTag = "intext:"
|
intextTag = "intext:"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoogleSearch is the Google implementation for Dorkgen
|
// GoogleSearch is the Google search implementation for Dorkgen
|
||||||
type GoogleSearch struct {
|
type GoogleSearch struct {
|
||||||
engineFactory
|
EngineFactory
|
||||||
tags []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func concat(tag string, value string, quotes bool) string {
|
|
||||||
if quotes {
|
|
||||||
return tag + "\"" + value + "\""
|
|
||||||
}
|
|
||||||
|
|
||||||
return tag + value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToString converts all tags to a single request
|
// 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.
|
// Site specifically searches that particular site and lists all the results for that site.
|
||||||
func (e *GoogleSearch) Site(site string) *GoogleSearch {
|
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
|
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.
|
// Intext searches for the occurrences of keywords all at once or one at a time.
|
||||||
func (e *GoogleSearch) Intext(text string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inurl searches for a URL matching one of the keywords.
|
// Inurl searches for a URL matching one of the keywords.
|
||||||
func (e *GoogleSearch) Inurl(url string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filetype searches for a particular filetype mentioned in the query.
|
// Filetype searches for a particular filetype mentioned in the query.
|
||||||
func (e *GoogleSearch) Filetype(filetype string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache shows the version of the web page that Google has in its cache.
|
// Cache shows the version of the web page that Google has in its cache.
|
||||||
func (e *GoogleSearch) Cache(url string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Related list web pages that are “similar” to a specified web page.
|
// Related list web pages that are “similar” to a specified web page.
|
||||||
func (e *GoogleSearch) Related(url string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ext searches for a particular file extension mentioned in the query.
|
// Ext searches for a particular file extension mentioned in the query.
|
||||||
func (e *GoogleSearch) Ext(ext string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude excludes some results.
|
// Exclude excludes some results.
|
||||||
func (e *GoogleSearch) Exclude(value string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +104,6 @@ func (e *GoogleSearch) Group(value string) *GoogleSearch {
|
||||||
|
|
||||||
// Intitle searches for occurrences of keywords in title all or one.
|
// Intitle searches for occurrences of keywords in title all or one.
|
||||||
func (e *GoogleSearch) Intitle(value string) *GoogleSearch {
|
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
|
return e
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue