feat: add QueryValues method
parent
723a968a27
commit
c339ef7be8
15
google.go
15
google.go
|
@ -32,16 +32,21 @@ func (e *GoogleSearch) String() string {
|
||||||
return strings.Join(e.tags, " ")
|
return strings.Join(e.tags, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToURL converts tags to an encoded Google Search URL
|
// QueryValues returns search request as URL values
|
||||||
func (e *GoogleSearch) ToURL() string {
|
func (e *GoogleSearch) QueryValues() url.Values {
|
||||||
baseURL, _ := url.Parse(searchURL)
|
|
||||||
|
|
||||||
tags := strings.Join(e.tags, " ")
|
tags := strings.Join(e.tags, " ")
|
||||||
|
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("q", tags)
|
params.Add("q", tags)
|
||||||
|
|
||||||
baseURL.RawQuery = params.Encode()
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToURL converts tags to an encoded Google Search URL
|
||||||
|
func (e *GoogleSearch) ToURL() string {
|
||||||
|
baseURL, _ := url.Parse(searchURL)
|
||||||
|
|
||||||
|
baseURL.RawQuery = e.QueryValues().Encode()
|
||||||
|
|
||||||
return baseURL.String()
|
return baseURL.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package dorkgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
assertion "github.com/stretchr/testify/assert"
|
assertion "github.com/stretchr/testify/assert"
|
||||||
|
@ -147,4 +148,18 @@ func TestInit(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(result, "site:linkedin.com (intext:\"1\" OR intext:\"2\") intitle:\"jordan\"", "they should be equal")
|
assert.Equal(result, "site:linkedin.com (intext:\"1\" OR intext:\"2\") intitle:\"jordan\"", "they should be equal")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("should return URL values", func(t *testing.T) {
|
||||||
|
dork = NewGoogleSearch()
|
||||||
|
|
||||||
|
result := dork.
|
||||||
|
Site("linkedin.com").
|
||||||
|
Group((NewGoogleSearch()).Intext("1").Or().Intext("2")).
|
||||||
|
Intitle("jordan").
|
||||||
|
QueryValues()
|
||||||
|
|
||||||
|
assert.Equal(url.Values{
|
||||||
|
"q": []string{"site:linkedin.com (intext:\"1\" OR intext:\"2\") intitle:\"jordan\""},
|
||||||
|
}, result, "they should be equal")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue