refactor auth api

This commit is contained in:
Valentine 2024-10-01 01:30:08 +03:00
parent 2de5a50e74
commit f257b131ff
3 changed files with 71 additions and 31 deletions

View file

@ -27,6 +27,7 @@ type Scraper struct {
oAuthToken string
oAuthSecret string
proxy string
userAgent string
searchMode SearchMode
wg sync.WaitGroup
}
@ -49,12 +50,14 @@ const (
// default http client timeout
const DefaultClientTimeout = 10 * time.Second
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
// New creates a Scraper object
func New() *Scraper {
jar, _ := cookiejar.New(nil)
return &Scraper{
bearerToken: bearerToken,
userAgent: DefaultUserAgent,
client: &http.Client{
Jar: jar,
Timeout: DefaultClientTimeout,
@ -169,3 +172,11 @@ func (s *Scraper) SetProxy(proxyAddr string) error {
}
return errors.New("only support http(s) or socks5 protocol")
}
func (s *Scraper) SetUserAgent(userAgent string) {
s.userAgent = userAgent
}
func (s *Scraper) GetUserAgent() string {
return s.userAgent
}