refactor: rename methods to camel case
parent
a1179e0de0
commit
22d5188e1b
|
@ -34,7 +34,7 @@ func New() *DuckDuckGo {
|
|||
return &DuckDuckGo{}
|
||||
}
|
||||
|
||||
func (d *DuckDuckGo) concat(tag string, value string, quotes bool) string {
|
||||
func (e *DuckDuckGo) join(tag string, value string, quotes bool) string {
|
||||
if quotes {
|
||||
return tag + "\"" + value + "\""
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ func (d *DuckDuckGo) concat(tag string, value string, quotes bool) string {
|
|||
}
|
||||
|
||||
// String converts all tags to a single request
|
||||
func (d *DuckDuckGo) String() string {
|
||||
return strings.Join(d.tags, " ")
|
||||
func (e *DuckDuckGo) String() string {
|
||||
return strings.Join(e.tags, " ")
|
||||
}
|
||||
|
||||
// QueryValues returns search request as URL values
|
||||
func (d *DuckDuckGo) QueryValues() url.Values {
|
||||
tags := strings.Join(d.tags, " ")
|
||||
func (e *DuckDuckGo) QueryValues() url.Values {
|
||||
tags := strings.Join(e.tags, " ")
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("q", tags)
|
||||
|
@ -58,115 +58,115 @@ func (d *DuckDuckGo) QueryValues() url.Values {
|
|||
}
|
||||
|
||||
// URL converts tags to an encoded Google Search URL
|
||||
func (d *DuckDuckGo) URL() string {
|
||||
func (e *DuckDuckGo) URL() string {
|
||||
baseURL, _ := url.Parse(searchURL)
|
||||
|
||||
baseURL.RawQuery = d.QueryValues().Encode()
|
||||
baseURL.RawQuery = e.QueryValues().Encode()
|
||||
|
||||
return baseURL.String()
|
||||
}
|
||||
|
||||
// Site specifically searches that particular site and lists all the results for that site.
|
||||
func (d *DuckDuckGo) Site(site string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(siteTag, site, false))
|
||||
return d
|
||||
func (e *DuckDuckGo) Site(site string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(siteTag, site, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Or puts an OR operator in the request
|
||||
func (d *DuckDuckGo) Or() *DuckDuckGo {
|
||||
d.tags = append(d.tags, operatorOr)
|
||||
return d
|
||||
func (e *DuckDuckGo) Or() *DuckDuckGo {
|
||||
e.tags = append(e.tags, operatorOr)
|
||||
return e
|
||||
}
|
||||
|
||||
// And puts an AND operator in the request
|
||||
func (d *DuckDuckGo) And() *DuckDuckGo {
|
||||
d.tags = append(d.tags, operatorAnd)
|
||||
return d
|
||||
func (e *DuckDuckGo) And() *DuckDuckGo {
|
||||
e.tags = append(e.tags, operatorAnd)
|
||||
return e
|
||||
}
|
||||
|
||||
// Intext searches for the occurrences of keywords all at once or one at a time.
|
||||
func (d *DuckDuckGo) Intext(text string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(intextTag, text, true))
|
||||
return d
|
||||
// InText searches for the occurrences of keywords all at once or one at a time.
|
||||
func (e *DuckDuckGo) InText(text string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(intextTag, text, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Inurl searches for a URL matching one of the keywords.
|
||||
func (d *DuckDuckGo) Inurl(url string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(urlTag, url, true))
|
||||
return d
|
||||
// InURL searches for a URL matching one of the keywords.
|
||||
func (e *DuckDuckGo) InURL(url string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(urlTag, url, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Filetype searches for a particular filetype mentioned in the query.
|
||||
func (d *DuckDuckGo) Filetype(filetype string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(filetypeTag, filetype, true))
|
||||
return d
|
||||
// FileType searches for a particular filetype mentioned in the query.
|
||||
func (e *DuckDuckGo) FileType(filetype string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(filetypeTag, filetype, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Ext searches for a particular file extension mentioned in the query.
|
||||
func (d *DuckDuckGo) Ext(ext string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(extTag, ext, false))
|
||||
return d
|
||||
func (e *DuckDuckGo) Ext(ext string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(extTag, ext, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Exclude excludes some results.
|
||||
func (d *DuckDuckGo) Exclude(tags *DuckDuckGo) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(excludeTag, tags.String(), false))
|
||||
return d
|
||||
func (e *DuckDuckGo) Exclude(tags *DuckDuckGo) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(excludeTag, tags.String(), false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Group isolate tags between parentheses
|
||||
func (d *DuckDuckGo) Group(tags *DuckDuckGo) *DuckDuckGo {
|
||||
d.tags = append(d.tags, "("+tags.String()+")")
|
||||
return d
|
||||
func (e *DuckDuckGo) Group(tags *DuckDuckGo) *DuckDuckGo {
|
||||
e.tags = append(e.tags, "("+tags.String()+")")
|
||||
return e
|
||||
}
|
||||
|
||||
// Intitle searches for occurrences of keywords in title all or one.
|
||||
func (d *DuckDuckGo) Intitle(value string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(intitleTag, value, true))
|
||||
return d
|
||||
// InTitle searches for occurrences of keywords in title all or one.
|
||||
func (e *DuckDuckGo) InTitle(value string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(intitleTag, value, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Plain allows you to add additional values as string without any kind of formatting.
|
||||
func (d *DuckDuckGo) Plain(value string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, value)
|
||||
return d
|
||||
func (e *DuckDuckGo) Plain(value string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, value)
|
||||
return e
|
||||
}
|
||||
|
||||
// AllInURL finds pages that include a specific keyword as part of their indexed URLs.
|
||||
func (d *DuckDuckGo) AllInURL(value string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(allInURLTag, value, true))
|
||||
return d
|
||||
func (e *DuckDuckGo) AllInURL(value string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(allInURLTag, value, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Location searches for specific region.
|
||||
// An iso location code is a short code for a country for example, Egypt is eg and USA is us.
|
||||
// https://en.wikipedia.org/wiki/ISO_3166-1
|
||||
func (d *DuckDuckGo) Location(isoCode string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(locationTag, isoCode, true))
|
||||
return d
|
||||
func (e *DuckDuckGo) Location(isoCode string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(locationTag, isoCode, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Feed finds RSS feed related to search term (i.e. rss).
|
||||
func (d *DuckDuckGo) Feed(feed string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(feedTag, feed, false))
|
||||
return d
|
||||
func (e *DuckDuckGo) Feed(feed string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(feedTag, feed, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// HasFeed finds webpages that contain both the term or terms for which you are querying and one or more RSS or Atom feeds.
|
||||
func (d *DuckDuckGo) HasFeed(url string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(hasfeedTag, url, true))
|
||||
return d
|
||||
func (e *DuckDuckGo) HasFeed(url string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(hasfeedTag, url, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Language returns websites that match the search term in a specified language.
|
||||
// See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for a complete list of ISO 639-1 codes you can use.
|
||||
func (d *DuckDuckGo) Language(lang string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(languageTag, lang, false))
|
||||
return d
|
||||
func (e *DuckDuckGo) Language(lang string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(languageTag, lang, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// AllInTitle finds pages that include a specific keyword as part of the indexed title tag.
|
||||
func (d *DuckDuckGo) AllInTitle(value string) *DuckDuckGo {
|
||||
d.tags = append(d.tags, d.concat(allintitleTag, value, true))
|
||||
return d
|
||||
func (e *DuckDuckGo) AllInTitle(value string) *DuckDuckGo {
|
||||
e.tags = append(e.tags, e.join(allintitleTag, value, true))
|
||||
return e
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestInit(t *testing.T) {
|
|||
dork = duckduckgo.New()
|
||||
|
||||
result := dork.
|
||||
Intext("text").
|
||||
InText("text").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "intext:\"text\"", "they should be equal")
|
||||
|
@ -56,7 +56,7 @@ func TestInit(t *testing.T) {
|
|||
dork = duckduckgo.New()
|
||||
|
||||
result := dork.
|
||||
Inurl("index.php").
|
||||
InURL("index.php").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
|
||||
|
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
|
|||
dork = duckduckgo.New()
|
||||
|
||||
result := dork.
|
||||
Filetype("pdf").
|
||||
FileType("pdf").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
|
||||
|
@ -171,9 +171,9 @@ func TestInit(t *testing.T) {
|
|||
dork = duckduckgo.New()
|
||||
|
||||
result := dork.
|
||||
Intitle("facebook").
|
||||
InTitle("facebook").
|
||||
And().
|
||||
Intitle("twitter").
|
||||
InTitle("twitter").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal")
|
||||
|
@ -184,7 +184,7 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(duckduckgo.New().Intext("1").Or().Intext("2")).
|
||||
Group(duckduckgo.New().InText("1").Or().InText("2")).
|
||||
String()
|
||||
|
||||
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal")
|
||||
|
@ -195,8 +195,8 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(duckduckgo.New().Intext("1").Or().Intext("2")).
|
||||
Intitle("jordan").
|
||||
Group(duckduckgo.New().InText("1").Or().InText("2")).
|
||||
InTitle("jordan").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal")
|
||||
|
@ -207,8 +207,8 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(duckduckgo.New().Intext("1").Or().Intext("2")).
|
||||
Intitle("jordan").
|
||||
Group(duckduckgo.New().InText("1").Or().InText("2")).
|
||||
InTitle("jordan").
|
||||
QueryValues()
|
||||
|
||||
assert.Equal(url.Values{
|
||||
|
|
|
@ -30,7 +30,7 @@ func New() *GoogleSearch {
|
|||
return &GoogleSearch{}
|
||||
}
|
||||
|
||||
func (_ *GoogleSearch) concat(tag string, value string, quotes bool) string {
|
||||
func (e *GoogleSearch) join(tag string, value string, quotes bool) string {
|
||||
if quotes {
|
||||
return tag + "\"" + value + "\""
|
||||
}
|
||||
|
@ -39,13 +39,13 @@ func (_ *GoogleSearch) concat(tag string, value string, quotes bool) string {
|
|||
}
|
||||
|
||||
// String converts all tags to a single request
|
||||
func (g *GoogleSearch) String() string {
|
||||
return strings.Join(g.tags, " ")
|
||||
func (e *GoogleSearch) String() string {
|
||||
return strings.Join(e.tags, " ")
|
||||
}
|
||||
|
||||
// QueryValues returns search request as URL values
|
||||
func (g *GoogleSearch) QueryValues() url.Values {
|
||||
tags := strings.Join(g.tags, " ")
|
||||
func (e *GoogleSearch) QueryValues() url.Values {
|
||||
tags := strings.Join(e.tags, " ")
|
||||
|
||||
params := url.Values{}
|
||||
params.Add("q", tags)
|
||||
|
@ -54,88 +54,88 @@ func (g *GoogleSearch) QueryValues() url.Values {
|
|||
}
|
||||
|
||||
// URL converts tags to an encoded Google Search URL
|
||||
func (g *GoogleSearch) URL() string {
|
||||
func (e *GoogleSearch) URL() string {
|
||||
baseURL, _ := url.Parse(searchURL)
|
||||
|
||||
baseURL.RawQuery = g.QueryValues().Encode()
|
||||
baseURL.RawQuery = e.QueryValues().Encode()
|
||||
|
||||
return baseURL.String()
|
||||
}
|
||||
|
||||
// Site specifically searches that particular site and lists all the results for that site.
|
||||
func (g *GoogleSearch) Site(site string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(siteTag, site, false))
|
||||
return g
|
||||
func (e *GoogleSearch) Site(site string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(siteTag, site, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Or puts an OR operator in the request
|
||||
func (g *GoogleSearch) Or() *GoogleSearch {
|
||||
g.tags = append(g.tags, operatorOr)
|
||||
return g
|
||||
func (e *GoogleSearch) Or() *GoogleSearch {
|
||||
e.tags = append(e.tags, operatorOr)
|
||||
return e
|
||||
}
|
||||
|
||||
// And puts an AND operator in the request
|
||||
func (g *GoogleSearch) And() *GoogleSearch {
|
||||
g.tags = append(g.tags, operatorAnd)
|
||||
return g
|
||||
func (e *GoogleSearch) And() *GoogleSearch {
|
||||
e.tags = append(e.tags, operatorAnd)
|
||||
return e
|
||||
}
|
||||
|
||||
// Intext searches for the occurrences of keywords all at once or one at a time.
|
||||
func (g *GoogleSearch) Intext(text string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(intextTag, text, true))
|
||||
return g
|
||||
// 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, e.join(intextTag, text, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Inurl searches for a URL matching one of the keywords.
|
||||
func (g *GoogleSearch) Inurl(url string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(urlTag, url, true))
|
||||
return g
|
||||
// InURL searches for a URL matching one of the keywords.
|
||||
func (e *GoogleSearch) InURL(url string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(urlTag, url, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Filetype searches for a particular filetype mentioned in the query.
|
||||
func (g *GoogleSearch) Filetype(filetype string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(filetypeTag, filetype, true))
|
||||
return g
|
||||
// FileType searches for a particular filetype mentioned in the query.
|
||||
func (e *GoogleSearch) FileType(filetype string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(filetypeTag, filetype, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Cache shows the version of the web page that Google has in its cache.
|
||||
func (g *GoogleSearch) Cache(url string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(cacheTag, url, true))
|
||||
return g
|
||||
func (e *GoogleSearch) Cache(url string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(cacheTag, url, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Related list web pages that are “similar” to a specified web page.
|
||||
func (g *GoogleSearch) Related(url string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(relatedTag, url, true))
|
||||
return g
|
||||
func (e *GoogleSearch) Related(url string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(relatedTag, url, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Ext searches for a particular file extension mentioned in the query.
|
||||
func (g *GoogleSearch) Ext(ext string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(extTag, ext, false))
|
||||
return g
|
||||
func (e *GoogleSearch) Ext(ext string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(extTag, ext, false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Exclude excludes some results.
|
||||
func (g *GoogleSearch) Exclude(tags *GoogleSearch) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(excludeTag, tags.String(), false))
|
||||
return g
|
||||
func (e *GoogleSearch) Exclude(tags *GoogleSearch) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(excludeTag, tags.String(), false))
|
||||
return e
|
||||
}
|
||||
|
||||
// Group isolate tags between parentheses
|
||||
func (g *GoogleSearch) Group(tags *GoogleSearch) *GoogleSearch {
|
||||
g.tags = append(g.tags, "("+tags.String()+")")
|
||||
return g
|
||||
func (e *GoogleSearch) Group(tags *GoogleSearch) *GoogleSearch {
|
||||
e.tags = append(e.tags, "("+tags.String()+")")
|
||||
return e
|
||||
}
|
||||
|
||||
// Intitle searches for occurrences of keywords in title all or one.
|
||||
func (g *GoogleSearch) Intitle(value string) *GoogleSearch {
|
||||
g.tags = append(g.tags, g.concat(intitleTag, value, true))
|
||||
return g
|
||||
// InTitle searches for occurrences of keywords in title all or one.
|
||||
func (e *GoogleSearch) InTitle(value string) *GoogleSearch {
|
||||
e.tags = append(e.tags, e.join(intitleTag, value, true))
|
||||
return e
|
||||
}
|
||||
|
||||
// Plain allows you to add additional values as string without any kind of formatting.
|
||||
func (g *GoogleSearch) Plain(value string) *GoogleSearch {
|
||||
g.tags = append(g.tags, value)
|
||||
return g
|
||||
func (e *GoogleSearch) Plain(value string) *GoogleSearch {
|
||||
e.tags = append(e.tags, value)
|
||||
return e
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestInit(t *testing.T) {
|
|||
dork = googlesearch.New()
|
||||
|
||||
result := dork.
|
||||
Intext("text").
|
||||
InText("text").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "intext:\"text\"", "they should be equal")
|
||||
|
@ -56,7 +56,7 @@ func TestInit(t *testing.T) {
|
|||
dork = googlesearch.New()
|
||||
|
||||
result := dork.
|
||||
Inurl("index.php").
|
||||
InURL("index.php").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
|
||||
|
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
|
|||
dork = googlesearch.New()
|
||||
|
||||
result := dork.
|
||||
Filetype("pdf").
|
||||
FileType("pdf").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
|
||||
|
@ -131,9 +131,9 @@ func TestInit(t *testing.T) {
|
|||
dork = googlesearch.New()
|
||||
|
||||
result := dork.
|
||||
Intitle("facebook").
|
||||
InTitle("facebook").
|
||||
And().
|
||||
Intitle("twitter").
|
||||
InTitle("twitter").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "intitle:\"facebook\" + intitle:\"twitter\"", "they should be equal")
|
||||
|
@ -144,7 +144,7 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(googlesearch.New().Intext("1").Or().Intext("2")).
|
||||
Group(googlesearch.New().InText("1").Or().InText("2")).
|
||||
String()
|
||||
|
||||
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\")", "they should be equal")
|
||||
|
@ -155,8 +155,8 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(googlesearch.New().Intext("1").Or().Intext("2")).
|
||||
Intitle("jordan").
|
||||
Group(googlesearch.New().InText("1").Or().InText("2")).
|
||||
InTitle("jordan").
|
||||
String()
|
||||
|
||||
assert.Equal(result, "site:linkedin.com (intext:\"1\" | intext:\"2\") intitle:\"jordan\"", "they should be equal")
|
||||
|
@ -167,8 +167,8 @@ func TestInit(t *testing.T) {
|
|||
|
||||
result := dork.
|
||||
Site("linkedin.com").
|
||||
Group(googlesearch.New().Intext("1").Or().Intext("2")).
|
||||
Intitle("jordan").
|
||||
Group(googlesearch.New().InText("1").Or().InText("2")).
|
||||
InTitle("jordan").
|
||||
QueryValues()
|
||||
|
||||
assert.Equal(url.Values{
|
||||
|
|
Loading…
Reference in New Issue