mirror of
https://github.com/karust/openserp.git
synced 2026-08-26 01:32:07 +08:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10decd5740 | ||
|
|
78a9f1e264 | ||
|
|
9f84a648f4 | ||
|
|
3c07c7789a | ||
|
|
3daa48e6a3 | ||
|
|
8bec5578c0 | ||
|
|
0146891076 | ||
|
|
f219c78d84 | ||
|
|
0fcfc06baa | ||
|
|
a4d459761e | ||
|
|
7cdd358cad | ||
|
|
6c8e205af2 | ||
|
|
b4ef23a913 | ||
|
|
0a347edc77 | ||
|
|
de0a6a80d4 | ||
|
|
74fc15a6e2 | ||
|
|
f8815b4560 | ||
|
|
49e9837878 | ||
|
|
fb8e8cd6fe | ||
|
|
f7654a52f0 | ||
|
|
8fdefb6ed5 | ||
|
|
81fc057c83 | ||
|
|
c35c5f134d | ||
|
|
83385711fe | ||
|
|
c980ca4dc4 | ||
|
|
d8c3700252 | ||
|
|
7f0f32ac4e | ||
|
|
ba94c69dd0 | ||
|
|
c387268d20 | ||
|
|
2f8ee2164d | ||
|
|
6691ebaadd | ||
|
|
8099dae3ce | ||
|
|
2f77dd6fe5 | ||
|
|
90f27c2974 | ||
|
|
ec03439b2f | ||
|
|
5ad89b2ea8 | ||
|
|
b2ffcf8477 | ||
|
|
21f12c5996 | ||
|
|
84e2d46c4b |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -24,3 +24,7 @@ logrus.txt
|
||||
logs.txt
|
||||
.release
|
||||
core/test/
|
||||
.aider*
|
||||
.gocache/
|
||||
openserp
|
||||
.gomodcache/
|
||||
|
||||
@@ -16,8 +16,13 @@ RUN go build -o /app/openserp .
|
||||
|
||||
FROM zenika/alpine-chrome:with-chromedriver
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY --from=builder /app/openserp /usr/local/bin/openserp
|
||||
ADD config.yaml /usr/src/app
|
||||
COPY config.yaml ./config.yaml
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:7000/health || exit 1
|
||||
|
||||
ENTRYPOINT ["openserp"]
|
||||
|
||||
|
||||
230
README.md
230
README.md
@@ -1,91 +1,179 @@
|
||||
# OpenSERP (Search Engine Results Page)
|
||||

|
||||
# OpenSERP (Search Engine Results)
|
||||
|
||||

|
||||
|
||||
[](https://goreportcard.com/report/github.com/karust/openserp)
|
||||
[](https://pkg.go.dev/github.com/karust/openserp)
|
||||
[](https://github.com/karust/openserp/releases)
|
||||
<!--  -->
|
||||
API access for search engines results if available isn't free.
|
||||
[](https://pkg.go.dev/github.com/karust/openserp)
|
||||
[](https://github.com/karust/openserp/releases)
|
||||
|
||||
Using OpenSERP, you can get search results from **Google**, **Yandex**, **Baidu** via API or CLI!
|
||||
<!-- [](https://hub.docker.com/repository/docker/karust/openserp) -->
|
||||
|
||||
See [Docker](#docker) and [CLI](#cli) usage examples below ([search](#search), [images](#images)).
|
||||
**OpenSERP** provides free API and CLI access to multiple search engines including **Google, Yandex, Baidu, Bing, and DuckDuckGo**. Get comprehensive search results without expensive API subscriptions!
|
||||
|
||||
## Features
|
||||
|
||||
- 🔍 **Multi-engine** - search with dedicated endpoints for each engine
|
||||
- 🌐 **Megasearch** - cross-engine aggregation with deduplication
|
||||
- 🖼 **Images** - image search is also available
|
||||
- 🎯 **Advanced filters** - language, date range, file type, and site queries
|
||||
- 🌍 **Configurable** - proxy, cache, and resilient mode support
|
||||
- 🐳 **Docker-ready** - local and container deployment
|
||||
|
||||
## Quick Start⚡️
|
||||
|
||||
### Docker (Recommended)
|
||||
|
||||
## Docker usage <a name="docker"></a> 🐳
|
||||
* Run API server:
|
||||
```bash
|
||||
# Use prebuilt image
|
||||
# Run the API server via prebuilt image
|
||||
docker run -p 127.0.0.1:7000:7000 -it karust/openserp serve -a 0.0.0.0 -p 7000
|
||||
|
||||
# Or build one and run using docker-compose.yaml
|
||||
docker-compose up --build
|
||||
# Or use docker-compose
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
### Request parameters
|
||||
| Param | Description |
|
||||
|-------|--------------------------------------------------------------|
|
||||
| text | Text to search |
|
||||
| lang | Search pages in selected language (`EN`, `DE`, `RU`...) |
|
||||
| date | Date in `YYYYMMDD..YYYYMMDD` format (e.g. 20181010..20231010) |
|
||||
| file | File extension to search (e.g. `PDF`, `DOC`) |
|
||||
| site | Search within a specific website |
|
||||
| limit | Limit the number of results
|
||||
| answers | Include google answers as negative rank indexes (e.g. `true`, `false`)
|
||||
### From source
|
||||
|
||||
### **Search**
|
||||
### *Example request*
|
||||
Get 20 **Google** results for `hello world`, only in English:
|
||||
```
|
||||
GET http:/127.0.0.1:7000/google/search?lang=EN&limit=20&text=hello world
|
||||
```
|
||||
You can replace `google` to `yandex` or `baidu` in query to change search engine.
|
||||
|
|
||||
|
||||
### *Example response*
|
||||
```JSON
|
||||
[
|
||||
{
|
||||
"rank": 1,
|
||||
"url": "https://en.wikipedia.org/wiki/%22Hello,_World!%22_program",
|
||||
"title": "\"Hello, World!\" program",
|
||||
"description": "A \"Hello, World!\" program is generally a computer program that ignores any input, and outputs or displays a message similar to \"Hello, World!\".",
|
||||
"ad": false
|
||||
},
|
||||
]
|
||||
```
|
||||
### **Images** **[WIP]**
|
||||
### *Example request*
|
||||
Get 100 **Google** results for `golden puppy`:
|
||||
```
|
||||
GET http://127.0.0.1:7000/google/image?text=golden puppy&limit=100
|
||||
```
|
||||
|
||||
|
||||
## CLI <a name="cli"></a> ⌨️
|
||||
* Use `-h` flag to see commands.
|
||||
* You can use `serve` command to serve API:
|
||||
```bash
|
||||
openserp serve
|
||||
git clone https://github.com/karust/openserp.git
|
||||
cd openserp
|
||||
go build -o openserp .
|
||||
./openserp serve
|
||||
```
|
||||
* Or print results in CLI using `search` command:
|
||||
|
||||
## 🌐 Megasearch & Megaimage
|
||||
|
||||
Search all engines at once:
|
||||
|
||||
```bash
|
||||
openserp search google "how to get banned from google fast" # Change `google` to `yandex` or `baidu`
|
||||
curl "http://127.0.0.1:7000/mega/search?text=golang&limit=10"
|
||||
```
|
||||
As a result you should get JSON output containting search results:
|
||||
|
||||
Search only selected engines:
|
||||
|
||||
```bash
|
||||
curl "http://127.0.0.1:7000/mega/search?text=golang&engines=duckduckgo,bing&limit=15"
|
||||
```
|
||||
|
||||
Advanced filtering:
|
||||
|
||||
```bash
|
||||
curl "http://127.0.0.1:7000/mega/search?text=Donald+Trump&engines=duckduckgo,bing&limit=20&date=20251005..20251005&lang=EN"
|
||||
```
|
||||
|
||||
API response example:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"rank": 1,
|
||||
"url": "https://www.cyberoptik.net/blog/6-sure-fire-ways-to-get-banned-from-google/",
|
||||
"title": "11 Sure-Fire Ways to Get Banned From Google | CyberOptik",
|
||||
"description": "How To Get Banned From Google · 1. Cloaking: The Art of Deception · 2. Plagiarism: Because Originality is Overrated · 3. Keyword Stuffing: More is Always Better · 4 ...",
|
||||
"ad": false
|
||||
},
|
||||
{
|
||||
"rank": 1,
|
||||
"url": "https://en.wikipedia.org/wiki/Golden_Retriever",
|
||||
"title": "Golden Retriever - Wikipedia",
|
||||
"description": "The Golden Retriever is a Scottish breed of retriever dog of medium size. It is characterised by a gentle and affectionate nature and a striking golden coat.",
|
||||
"ad": false,
|
||||
"engine": "duckduckgo"
|
||||
},
|
||||
{
|
||||
"rank": 2,
|
||||
"url": "https://www.bing.com/ck/a?!&&p=6f15ac4589858d0a104cd6f55cc8",
|
||||
"title": "Golden Retriever Dog Forums",
|
||||
"description": "Oct 20, 2024 · Back in the 1970s, Golden Retrievers routinely lived until 16 and 17 years old, they are now...",
|
||||
"ad": false,
|
||||
"engine": "bing"
|
||||
},
|
||||
{
|
||||
"rank": 3,
|
||||
"url": "http://www.baidu.com/link?url==2544q3ugc68j0scVxdpWCSX-gl2AmuCy1l7uRR3loIfS1",
|
||||
"title": "golden retrievers是什么意思",
|
||||
"description": "2025年9月21日golden retrievers 读音:美英 golden retrievers基本解释 金毛猎犬 分词解释 golden金(黄)色的...",
|
||||
"ad": false,
|
||||
"engine": "baidu"
|
||||
}
|
||||
]
|
||||
```
|
||||
```
|
||||
|
||||
## License
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
|
||||
Image search:
|
||||
|
||||
## Bugs + Questions 👾
|
||||
If you have some issues/bugs/questions, feel free to open an issue.
|
||||
```bash
|
||||
curl "http://127.0.0.1:7000/mega/image?text=golang logo&limit=20"
|
||||
```
|
||||
|
||||
List available engines:
|
||||
|
||||
```bash
|
||||
curl "http://127.0.0.1:7000/mega/engines"
|
||||
```
|
||||
|
||||
**Available engines:** `google`, `yandex`, `baidu`, `bing`, `duckduckgo`
|
||||
|
||||
## 🔍 Individual Engine APIs
|
||||
|
||||
Common query parameters:
|
||||
|
||||
| Parameter | Description | Example |
|
||||
| --------- | -------------------- | --------------------------------- |
|
||||
| `text` | Search query | `golang programming` |
|
||||
| `lang` | Language code | `EN`, `DE`, `RU`, `ES` |
|
||||
| `date` | Date range | `20230101..20231231` |
|
||||
| `file` | File extension | `PDF`, `DOC`, `XLS` |
|
||||
| `site` | Site-specific search | `github.com`, `stackoverflow.com` |
|
||||
| `limit` | Number of results | `10`, `25`, `50` |
|
||||
|
||||
Engine-specific parameters:
|
||||
|
||||
| Parameter | Supported engines | Notes |
|
||||
| --------- | ----------------------------------- | ------------------------------------------------------------------ |
|
||||
| `start` | `google`, `bing`, `yandex`, `baidu` | Web search pagination offset. |
|
||||
| `filter` | `google` | Duplicate filter (`true` hides similar, `false` includes similar). |
|
||||
| `answers` | `google` | Include Google answer boxes in output with negative ranks. |
|
||||
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
curl "http://127.0.0.1:7000/duck/search?text=golang&limit=7"
|
||||
curl "http://127.0.0.1:7000/google/search?text=golang&lang=EN&limit=10"
|
||||
curl "http://127.0.0.1:7000/bing/search?text=golang&limit=10&start=20"
|
||||
curl "http://127.0.0.1:7000/yandex/search?text=golang&limit=10&start=10"
|
||||
curl "http://127.0.0.1:7000/bing/image?text=golang&limit=20"
|
||||
```
|
||||
|
||||
## 🌍 Proxy Support
|
||||
|
||||
OpenSERP supports HTTP and SOCKS5 proxies.
|
||||
|
||||
Simple global proxy:
|
||||
|
||||
```bash
|
||||
./openserp serve --proxy socks5://127.0.0.1:1080
|
||||
./openserp search bing "query" --proxy http://user:pass@127.0.0.1:8080
|
||||
```
|
||||
|
||||
Advanced proxy configuration is available in [config.yaml](./config.yaml).
|
||||
You can enable tagged proxy pools and per-request override via `X-Use-Proxy: <tag>` or `X-Use-Proxy: direct`.
|
||||
|
||||
## Health & Stats
|
||||
|
||||
```bash
|
||||
curl -i "http://127.0.0.1:7000/health"
|
||||
curl "http://127.0.0.1:7000/stats"
|
||||
curl "http://127.0.0.1:7000/stats/cache"
|
||||
curl "http://127.0.0.1:7000/stats/proxy"
|
||||
curl "http://127.0.0.1:7000/stats/cb"
|
||||
```
|
||||
|
||||
Useful response headers in server mode: `X-Cache`, `X-Fallback-Engine`,`X-Proxy-Mode`, `X-Proxy-Tag`, `X-Proxy-Used`
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License. See [LICENSE](LICENSE).
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
Contributions are welcome. Please feel free to submit a pull request.
|
||||
|
||||
## 👾 Issues & Support
|
||||
|
||||
If you encounter issues or have questions:
|
||||
|
||||
- Open an issue on GitHub
|
||||
- Check existing issues for similar reports
|
||||
- Review the documentation and example config
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
@@ -35,12 +34,14 @@ type imageDataJson struct {
|
||||
type Baidu struct {
|
||||
core.Browser
|
||||
core.SearchEngineOptions
|
||||
logger *core.EngineLogger
|
||||
}
|
||||
|
||||
func New(browser core.Browser, opts core.SearchEngineOptions) *Baidu {
|
||||
baid := Baidu{Browser: browser}
|
||||
opts.Init()
|
||||
baid.SearchEngineOptions = opts
|
||||
baid.logger = core.NewEngineLogger("Baidu")
|
||||
return &baid
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ func (baid *Baidu) isTimeout(page *rod.Page) bool {
|
||||
}
|
||||
|
||||
func (baid *Baidu) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Baidu search, query: %+v", query)
|
||||
baid.logger.Debug("Starting search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
@@ -74,12 +75,15 @@ func (baid *Baidu) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page := baid.Navigate(url)
|
||||
page, err := baid.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results, err := page.Timeout(baid.Timeout).Search("div.c-container.new-pmd")
|
||||
if err != nil {
|
||||
defer page.Close()
|
||||
logrus.Errorf("Cannot parse search results: %s", err)
|
||||
baid.logger.Error("Cannot parse search results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
@@ -88,10 +92,10 @@ func (baid *Baidu) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
defer page.Close()
|
||||
|
||||
if baid.isCaptcha(page) {
|
||||
logrus.Errorf("Baidu captcha occurred during: %s", url)
|
||||
baid.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
} else if baid.isTimeout(page) {
|
||||
logrus.Errorf("Baidu timeout occurred during: %s", url)
|
||||
baid.logger.Error("Timeout occurred: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
return nil, nil
|
||||
@@ -110,13 +114,13 @@ func (baid *Baidu) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
linkText, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Error("No `href` tag found")
|
||||
baid.logger.Error("Missing href tag")
|
||||
}
|
||||
|
||||
// Get title
|
||||
title, err := link.Text()
|
||||
if err != nil {
|
||||
logrus.Error("Cannot extract text from title")
|
||||
baid.logger.Error("Failed to extract title")
|
||||
title = "No title"
|
||||
}
|
||||
|
||||
@@ -127,22 +131,22 @@ func (baid *Baidu) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
desc = strings.ReplaceAll(desc, title, "")
|
||||
|
||||
gR := core.SearchResult{Rank: i + 1, URL: linkText.String(), Title: title, Description: desc}
|
||||
gR := core.SearchResult{Rank: query.Start + i + 1, URL: linkText.String(), Title: title, Description: desc}
|
||||
searchResults = append(searchResults, gR)
|
||||
}
|
||||
|
||||
if !baid.LeavePageOpen {
|
||||
if !baid.Browser.LeavePageOpen {
|
||||
err = page.Close()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
baid.logger.Error("Page close error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return searchResults, nil
|
||||
return core.DeduplicateResults(searchResults), nil
|
||||
}
|
||||
|
||||
func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Baidu Image search, query: %+v", query)
|
||||
baid.logger.Debug("Starting image search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
searchPage := 0
|
||||
@@ -154,8 +158,12 @@ func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
|
||||
// Get anti-crawler cookies first, then reload page
|
||||
page := baid.Navigate(url)
|
||||
if !baid.LeavePageOpen {
|
||||
page, err := baid.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !baid.Browser.LeavePageOpen {
|
||||
defer page.Close()
|
||||
}
|
||||
page.Reload()
|
||||
@@ -164,7 +172,7 @@ func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
result, err := page.Timeout(baid.Timeout).Search("body > pre")
|
||||
if err != nil {
|
||||
defer page.Close()
|
||||
logrus.Errorf("Cannot parse search results: %s", err)
|
||||
baid.logger.Error("Cannot parse search results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
@@ -173,10 +181,10 @@ func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
defer page.Close()
|
||||
|
||||
if baid.isCaptcha(page) {
|
||||
logrus.Errorf("Baidu captcha occurred during: %s", url)
|
||||
baid.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
} else if baid.isTimeout(page) {
|
||||
logrus.Errorf("Baidu timeout occurred during: %s", url)
|
||||
baid.logger.Error("Timeout occurred: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
return nil, nil
|
||||
@@ -200,7 +208,7 @@ func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
err = json.Unmarshal([]byte(fixedJson), &data)
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot unmarshal JSON: %v\nData: %v", err, jsonText)
|
||||
baid.logger.Error("Failed to unmarshal JSON: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -226,10 +234,10 @@ func (baid *Baidu) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
searchPage += 1
|
||||
|
||||
if !baid.LeavePageOpen {
|
||||
if !baid.Browser.LeavePageOpen {
|
||||
page.Close()
|
||||
}
|
||||
}
|
||||
|
||||
return searchResults, nil
|
||||
return core.DeduplicateResults(searchResults), nil
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func baiduRequest(searchURL string) (*http.Response, error) {
|
||||
baseClient := &http.Client{}
|
||||
func baiduRequest(searchURL string, query core.Query) (*http.Response, error) {
|
||||
baseClient, err := core.NewRawHTTPClient(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", searchURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -27,7 +31,7 @@ func baiduRequest(searchURL string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func baiduResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
doc, err := goquery.NewDocumentFromResponse(response)
|
||||
doc, err := goquery.NewDocumentFromReader(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +83,7 @@ func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
logrus.Debugf("Baidu URL built: %s", googleURL)
|
||||
|
||||
res, err := baiduRequest(googleURL)
|
||||
res, err := baiduRequest(googleURL, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -89,7 +93,12 @@ func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if query.Start > 0 {
|
||||
for i := range results {
|
||||
results[i].Rank = query.Start + i + 1
|
||||
}
|
||||
}
|
||||
logrus.Debugf("Baidu Raw results : %v", results)
|
||||
|
||||
return results, nil
|
||||
return core.DeduplicateResults(results), nil
|
||||
}
|
||||
|
||||
13
baidu/url.go
13
baidu/url.go
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func dateToTimestamp(date string) (int64, error) {
|
||||
layout := "20060201"
|
||||
layout := "20060102"
|
||||
t, err := time.Parse(layout, date)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -55,17 +55,24 @@ func BuildURL(q core.Query) (string, error) {
|
||||
|
||||
if q.LangCode != "" {
|
||||
//params.Add("rqlang", q.LangCode)
|
||||
logrus.Warn("Baidu's Language specific search not supported yet")
|
||||
logrus.Warn("Language search not supported")
|
||||
}
|
||||
|
||||
if q.Filetype != "" {
|
||||
//params.Add("ft", q.Filetype)
|
||||
logrus.Warn("Baidu's File search not supported yet")
|
||||
logrus.Warn("File search not supported")
|
||||
}
|
||||
|
||||
if q.Limit != 0 {
|
||||
params.Add("rn", strconv.Itoa(q.Limit))
|
||||
}
|
||||
if q.Start < 0 {
|
||||
return "", errors.New("incorrect start provided")
|
||||
}
|
||||
if q.Start > 0 {
|
||||
// Baidu uses "pn" as result offset for pagination.
|
||||
params.Add("pn", strconv.Itoa(q.Start))
|
||||
}
|
||||
|
||||
if len(params.Get("wd")) == 0 {
|
||||
return "", errors.New("Empty query built")
|
||||
|
||||
161
bing/bing_test.go
Normal file
161
bing/bing_test.go
Normal file
@@ -0,0 +1,161 @@
|
||||
package bing
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
var browser *core.Browser
|
||||
|
||||
func init() {
|
||||
opts := core.BrowserOpts{IsHeadless: false, IsLeakless: false, UseStealth: true, Timeout: time.Second * 5, LeavePageOpen: true}
|
||||
browser, _ = core.NewBrowser(opts)
|
||||
}
|
||||
|
||||
func TestSearchBing(t *testing.T) {
|
||||
bing := New(*browser, core.SearchEngineOptions{})
|
||||
|
||||
query := core.Query{Text: "golang programming", Limit: 10}
|
||||
results, err := bing.Search(query)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot [SearchBing]: %s", err)
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
t.Fatalf("[SearchBing] returned empty result")
|
||||
}
|
||||
|
||||
// Check that we have some basic fields populated
|
||||
firstResult := results[0]
|
||||
if firstResult.Title == "" {
|
||||
t.Errorf("First result missing title: %+v", firstResult)
|
||||
}
|
||||
if firstResult.URL == "" {
|
||||
t.Errorf("First result missing URL: %+v", firstResult)
|
||||
}
|
||||
if firstResult.Rank == 0 {
|
||||
t.Errorf("First result missing rank: %+v", firstResult)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildImageURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
query core.Query
|
||||
wantErr bool
|
||||
wantCont string
|
||||
}{
|
||||
{
|
||||
name: "basic image query",
|
||||
query: core.Query{Text: "test"},
|
||||
wantErr: false,
|
||||
wantCont: "q=test",
|
||||
},
|
||||
{
|
||||
name: "image query with site",
|
||||
query: core.Query{Text: "cats", Site: "example.com"},
|
||||
wantErr: false,
|
||||
wantCont: "q=cats+site%3Aexample.com",
|
||||
},
|
||||
{
|
||||
name: "image query with filetype",
|
||||
query: core.Query{Text: "dogs", Filetype: "png"},
|
||||
wantErr: false,
|
||||
wantCont: "q=dogs+filetype%3Apng",
|
||||
},
|
||||
{
|
||||
name: "empty query",
|
||||
query: core.Query{Text: ""},
|
||||
wantErr: true,
|
||||
wantCont: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := BuildImageURL(tt.query)
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("BuildImageURL() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if !tt.wantErr && got != "" {
|
||||
if !strings.Contains(got, tt.wantCont) {
|
||||
t.Errorf("BuildImageURL() = %v, should contain %v", got, tt.wantCont)
|
||||
}
|
||||
|
||||
// Test that URL is valid
|
||||
_, err := url.Parse(got)
|
||||
if err != nil {
|
||||
t.Errorf("BuildImageURL() returned invalid URL: %v", err)
|
||||
}
|
||||
|
||||
// Should be a Bing images URL
|
||||
if !strings.Contains(got, "bing.com/images/search") {
|
||||
t.Errorf("BuildImageURL() should return Bing images URL, got: %v", got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBingImageSearch(t *testing.T) {
|
||||
bing := New(*browser, core.SearchEngineOptions{RateTime: 5})
|
||||
|
||||
query := core.Query{
|
||||
Text: "golden puppy",
|
||||
Limit: 25,
|
||||
Filetype: "jpg",
|
||||
}
|
||||
|
||||
results, err := bing.SearchImage(query)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot search Bing images: %s", err)
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
t.Fatalf("Bing image search returned empty result")
|
||||
}
|
||||
|
||||
// Check that we have image results with proper fields
|
||||
firstResult := results[0]
|
||||
if firstResult.URL == "" {
|
||||
t.Errorf("First result missing image URL: %+v", firstResult)
|
||||
}
|
||||
if firstResult.Title == "" {
|
||||
t.Errorf("First result missing title: %+v", firstResult)
|
||||
}
|
||||
|
||||
// Check that we have either image URL or source URL
|
||||
hasImageURL := firstResult.URL != ""
|
||||
hasSourceURL := firstResult.URL != ""
|
||||
if !hasImageURL && !hasSourceURL {
|
||||
t.Errorf("First result should have either image URL or source URL: %+v", firstResult)
|
||||
}
|
||||
|
||||
// For image results, URL should typically point to an image file
|
||||
if hasImageURL {
|
||||
// Check if it looks like an image URL (common extensions)
|
||||
imageExtensions := []string{".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"}
|
||||
hasImageExtension := false
|
||||
for _, ext := range imageExtensions {
|
||||
if strings.Contains(strings.ToLower(firstResult.URL), ext) {
|
||||
hasImageExtension = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasImageExtension {
|
||||
t.Logf("Image URL doesn't have common extension (might be valid): %s", firstResult.URL)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("Found %d image results", len(results))
|
||||
t.Logf("First result - Title: %s", firstResult.Title)
|
||||
t.Logf("First result - Image URL: %s", firstResult.URL)
|
||||
t.Logf("First result - Source URL: %s", firstResult.URL)
|
||||
}
|
||||
348
bing/search.go
Normal file
348
bing/search.go
Normal file
@@ -0,0 +1,348 @@
|
||||
package bing
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/go-rod/rod/lib/proto"
|
||||
"github.com/karust/openserp/core"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type Bing struct {
|
||||
core.Browser
|
||||
core.SearchEngineOptions
|
||||
logger *core.EngineLogger
|
||||
}
|
||||
|
||||
func New(browser core.Browser, opts core.SearchEngineOptions) *Bing {
|
||||
bing := Bing{Browser: browser}
|
||||
opts.Init()
|
||||
bing.SearchEngineOptions = opts
|
||||
bing.logger = core.NewEngineLogger("Bing")
|
||||
return &bing
|
||||
}
|
||||
|
||||
func (bing *Bing) Name() string {
|
||||
return "bing"
|
||||
}
|
||||
|
||||
func (bing *Bing) GetRateLimiter() *rate.Limiter {
|
||||
ratelimit := rate.Every(bing.GetRatelimit())
|
||||
return rate.NewLimiter(ratelimit, bing.RateBurst)
|
||||
}
|
||||
|
||||
func (bing *Bing) getTotalResults(page *rod.Page) (int, error) {
|
||||
results, err := page.Timeout(bing.GetSelectorTimeout()).Elements("li.b_algo")
|
||||
if err != nil {
|
||||
return 0, errors.New("Cannot find result elements: " + err.Error())
|
||||
}
|
||||
return len(results), nil
|
||||
}
|
||||
|
||||
func (bing *Bing) checkCaptcha(page *rod.Page) bool {
|
||||
if page == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if info, err := page.Info(); err == nil {
|
||||
url := strings.ToLower(info.URL)
|
||||
if strings.Contains(url, "turing") || strings.Contains(url, "captcha") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
timeout := bing.GetSelectorTimeout() / 2
|
||||
if timeout <= 0 {
|
||||
timeout = time.Second * 2
|
||||
}
|
||||
|
||||
selectors := []string{
|
||||
"div.captcha",
|
||||
"div.captcha_header",
|
||||
}
|
||||
|
||||
for _, selector := range selectors {
|
||||
has, err, _ := page.Timeout(timeout).Has(selector)
|
||||
if err == nil && has {
|
||||
bing.logger.Debug("Captcha detected: %s", selector)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (bing *Bing) acceptCookies(page *rod.Page) {
|
||||
consentBtn, err := page.Timeout(bing.Timeout / 10).Element("button#bnp_btn_accept")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
consentBtn.Click(proto.InputMouseButtonLeft, 1)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
|
||||
func (bing *Bing) close(page *rod.Page) {
|
||||
if !bing.Browser.LeavePageOpen {
|
||||
if page != nil {
|
||||
err := page.Close()
|
||||
if err != nil {
|
||||
bing.logger.Debug("Page close error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bing *Bing) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
bing.logger.Debug("Starting search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
url, err := BuildURL(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page, err := bing.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer bing.close(page)
|
||||
|
||||
page.WaitLoad()
|
||||
|
||||
if bing.checkCaptcha(page) {
|
||||
bing.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
|
||||
bing.acceptCookies(page)
|
||||
page.WaitLoad()
|
||||
|
||||
organicElements, err := page.Timeout(bing.Timeout).Elements("li.b_algo")
|
||||
if err != nil {
|
||||
bing.logger.Error("Cannot parse organic results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
adElements, err := page.Timeout(bing.Timeout).Elements("li.b_ad")
|
||||
if err != nil {
|
||||
bing.logger.Debug("No ads found")
|
||||
}
|
||||
|
||||
totalResults, err := bing.getTotalResults(page)
|
||||
if err != nil {
|
||||
bing.logger.Debug("Failed to get total results: %v", err)
|
||||
}
|
||||
bing.logger.Info("Found %d results (%d ads)", totalResults, len(adElements))
|
||||
|
||||
rank := query.Start
|
||||
for _, result := range organicElements {
|
||||
srchRes := core.SearchResult{}
|
||||
|
||||
titleElem, err := result.Element("a")
|
||||
if err != nil {
|
||||
bing.logger.Debug("Missing title")
|
||||
continue
|
||||
}
|
||||
srchRes.Title, _ = titleElem.Text()
|
||||
|
||||
href, err := titleElem.Property("href")
|
||||
if err != nil {
|
||||
bing.logger.Debug("Missing URL")
|
||||
continue
|
||||
}
|
||||
srchRes.URL = href.String()
|
||||
|
||||
var desc string
|
||||
if descElem, err := result.Element("div.b_caption p"); err == nil {
|
||||
desc, _ = descElem.Text()
|
||||
} else if descElem, err := result.Element("div.b_caption div"); err == nil {
|
||||
desc, _ = descElem.Text()
|
||||
} else if descElem, err := result.Element("p"); err == nil {
|
||||
desc, _ = descElem.Text()
|
||||
} else {
|
||||
fullText, _ := result.Text()
|
||||
desc = strings.TrimSpace(strings.Replace(fullText, srchRes.Title, "", 1))
|
||||
}
|
||||
srchRes.Description = desc
|
||||
|
||||
rank++
|
||||
srchRes.Rank = rank
|
||||
srchRes.Ad = false
|
||||
|
||||
searchResults = append(searchResults, srchRes)
|
||||
}
|
||||
|
||||
for _, adResult := range adElements {
|
||||
srchRes := core.SearchResult{Ad: true}
|
||||
|
||||
titleElem, err := adResult.Element("h2 a")
|
||||
if err != nil {
|
||||
bing.logger.Debug("Ad missing title")
|
||||
continue
|
||||
}
|
||||
srchRes.Title, _ = titleElem.Text()
|
||||
|
||||
href, err := titleElem.Property("href")
|
||||
if err != nil {
|
||||
bing.logger.Debug("Ad missing URL")
|
||||
continue
|
||||
}
|
||||
srchRes.URL = href.String()
|
||||
|
||||
if descElem, err := adResult.Element("p"); err == nil {
|
||||
srchRes.Description, _ = descElem.Text()
|
||||
}
|
||||
|
||||
// Mark ads with negative rank
|
||||
srchRes.Rank = -1
|
||||
searchResults = append(searchResults, srchRes)
|
||||
}
|
||||
|
||||
// Deduplicate results
|
||||
deduped := core.DeduplicateResults(searchResults)
|
||||
|
||||
// Trim to exact limit if necessary (only organic results, not ads)
|
||||
if query.Limit > 0 {
|
||||
organicResults := []core.SearchResult{}
|
||||
adResults := []core.SearchResult{}
|
||||
|
||||
for _, result := range deduped {
|
||||
if result.Ad {
|
||||
adResults = append(adResults, result)
|
||||
} else {
|
||||
organicResults = append(organicResults, result)
|
||||
}
|
||||
}
|
||||
|
||||
// Trim organic results to limit
|
||||
if len(organicResults) > query.Limit {
|
||||
organicResults = organicResults[:query.Limit]
|
||||
}
|
||||
|
||||
// Combine back: organic results + ads
|
||||
deduped = append(organicResults, adResults...)
|
||||
}
|
||||
|
||||
return deduped, nil
|
||||
}
|
||||
|
||||
// BingImageData represents the JSON structure in the m attribute of image elements
|
||||
type BingImageData struct {
|
||||
T string `json:"t"` // Title
|
||||
Desc string `json:"desc"` // Description
|
||||
IMGURL string `json:"imgurl"` // Original image URL
|
||||
W int `json:"w"` // Width
|
||||
H int `json:"h"` // Height
|
||||
PURL string `json:"purl"` // Page URL
|
||||
TURL string `json:"turl"` // Thumbnail URL
|
||||
MURL string `json:"murl"` // Image URL
|
||||
}
|
||||
|
||||
// SearchImage performs Bing image search and returns results
|
||||
func (bing *Bing) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
bing.logger.Debug("Starting image search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
// Build Bing image search URL
|
||||
url, err := BuildImageURL(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page, err := bing.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer bing.close(page)
|
||||
|
||||
page.WaitLoad()
|
||||
|
||||
// Check for captcha
|
||||
if bing.checkCaptcha(page) {
|
||||
bing.logger.Error("Captcha detected during image search: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
|
||||
// Accept cookies if present
|
||||
bing.acceptCookies(page)
|
||||
|
||||
// Wait for image results to load
|
||||
page.WaitLoad()
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
// Find all image result containers using CSS selector
|
||||
imageContainers, err := page.Timeout(bing.Timeout).Elements("div.iuscp, div.isv")
|
||||
if err != nil {
|
||||
bing.logger.Error("Cannot parse image results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
if len(imageContainers) == 0 {
|
||||
return nil, errors.New("no image results found")
|
||||
}
|
||||
|
||||
bing.logger.Info("Found %d image elements", len(imageContainers))
|
||||
|
||||
rank := 0
|
||||
for _, c := range imageContainers {
|
||||
srchRes := core.SearchResult{}
|
||||
|
||||
// Get the <a> element inside the div
|
||||
linkElem, err := c.Element("a")
|
||||
if err != nil {
|
||||
bing.logger.Debug("Missing <a> element")
|
||||
continue
|
||||
}
|
||||
|
||||
// Extract image metadata from m attribute (contains JSON)
|
||||
mAttr, err := linkElem.Attribute("m")
|
||||
if err != nil || mAttr == nil {
|
||||
bing.logger.Debug("Missing m attribute")
|
||||
continue
|
||||
}
|
||||
|
||||
// Ensure we have valid JSON data to unmarshal
|
||||
jsonData := []byte(*mAttr)
|
||||
if len(jsonData) == 0 {
|
||||
bing.logger.Debug("Empty JSON data")
|
||||
continue
|
||||
}
|
||||
|
||||
// Initialize imgData properly
|
||||
var imgData BingImageData
|
||||
err = json.Unmarshal(jsonData, &imgData)
|
||||
if err != nil {
|
||||
bing.logger.Debug("Failed to parse JSON: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Extract information from the parsed data
|
||||
srchRes.Title = imgData.T
|
||||
srchRes.URL = imgData.IMGURL
|
||||
srchRes.Description = imgData.Desc
|
||||
|
||||
// Add dimensions to description if available
|
||||
if imgData.W > 0 && imgData.H > 0 {
|
||||
srchRes.Description += fmt.Sprintf(" (%dx%d)", imgData.W, imgData.H)
|
||||
}
|
||||
|
||||
// Get the page URL
|
||||
if imgData.MURL != "" {
|
||||
srchRes.URL = imgData.MURL
|
||||
}
|
||||
|
||||
rank++
|
||||
srchRes.Rank = rank
|
||||
|
||||
searchResults = append(searchResults, srchRes)
|
||||
}
|
||||
|
||||
return searchResults, nil
|
||||
}
|
||||
129
bing/url.go
Normal file
129
bing/url.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package bing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func BuildURL(q core.Query) (string, error) {
|
||||
base, err := url.Parse("https://www.bing.com")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
base.Path += "search"
|
||||
params := url.Values{}
|
||||
|
||||
// Set search query text with operators
|
||||
if q.Text != "" || q.Site != "" || q.Filetype != "" {
|
||||
text := q.Text
|
||||
if q.Site != "" {
|
||||
text += " site:" + q.Site
|
||||
}
|
||||
if q.Filetype != "" {
|
||||
text += " filetype:" + q.Filetype
|
||||
}
|
||||
|
||||
logrus.Tracef("Query text: %s", text)
|
||||
params.Add("q", text)
|
||||
}
|
||||
|
||||
if len(params.Get("q")) == 0 {
|
||||
return "", errors.New("empty query built")
|
||||
}
|
||||
|
||||
if q.LangCode != "" {
|
||||
params.Add("setlang", strings.ToLower(q.LangCode))
|
||||
}
|
||||
|
||||
// Set result offset (pagination) - Bing uses "first" parameter.
|
||||
// When first is present, Bing may ignore custom count and return default page size.
|
||||
if q.Start < 0 {
|
||||
return "", errors.New("incorrect start provided")
|
||||
}
|
||||
if q.Start > 0 {
|
||||
// Bing uses 1-based first-result index for pagination.
|
||||
params.Add("first", strconv.Itoa(q.Start+1))
|
||||
} else if q.Limit > 0 {
|
||||
params.Add("count", strconv.Itoa(q.Limit))
|
||||
}
|
||||
|
||||
// Set search date range - Bing supports date filtering via query text
|
||||
if q.DateInterval != "" {
|
||||
intervals := strings.Split(q.DateInterval, "..")
|
||||
if len(intervals) != 2 {
|
||||
return "", errors.New("incorrect date interval provided, expected format: YYYYMMDD..YYYYMMDD")
|
||||
}
|
||||
|
||||
// Convert YYYYMMDD to YYYY-MM-DD format for Bing
|
||||
startDate, err := time.Parse("20060102", intervals[0])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid start date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
endDate, err := time.Parse("20060102", intervals[1])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid end date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
// Add date range to the search query text (Bing supports this format)
|
||||
dateRange := fmt.Sprintf(" after:%s before:%s",
|
||||
startDate.Format("2006-01-02"),
|
||||
endDate.Format("2006-01-02"))
|
||||
|
||||
// Update the query text to include date range
|
||||
currentQuery := params.Get("q")
|
||||
params.Set("q", currentQuery+dateRange)
|
||||
}
|
||||
|
||||
// Bing-specific parameters for consistent results
|
||||
params.Add("form", "QBLH") // Standard search form
|
||||
params.Add("qs", "HS") // Query suggestions
|
||||
params.Add("sp", "-1") // Search provider
|
||||
params.Add("pq", params.Get("q")) // Previous query
|
||||
|
||||
base.RawQuery = params.Encode()
|
||||
return base.String(), nil
|
||||
}
|
||||
|
||||
func BuildImageURL(q core.Query) (string, error) {
|
||||
base, err := url.Parse("https://www.bing.com")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
base.Path += "images/search"
|
||||
params := url.Values{}
|
||||
|
||||
if q.Text != "" || q.Site != "" {
|
||||
text := q.Text
|
||||
if q.Site != "" {
|
||||
text += " site:" + q.Site
|
||||
}
|
||||
params.Add("q", text)
|
||||
}
|
||||
|
||||
if len(params.Get("q")) == 0 {
|
||||
return "", errors.New("empty query built")
|
||||
}
|
||||
|
||||
// Add common parameters
|
||||
if q.LangCode != "" {
|
||||
params.Add("setlang", strings.ToLower(q.LangCode))
|
||||
}
|
||||
|
||||
// Image-specific parameters
|
||||
params.Add("form", "HDRSC2")
|
||||
params.Add("first", "1")
|
||||
params.Add("scenario", "ImageBasicHover")
|
||||
|
||||
base.RawQuery = params.Encode()
|
||||
return base.String(), nil
|
||||
}
|
||||
30
cmd/proxy_policy.go
Normal file
30
cmd/proxy_policy.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
func buildEngineProxyPolicyMap() map[string]string {
|
||||
return map[string]string{
|
||||
"google": config.GoogleConfig.Proxy,
|
||||
"yandex": config.YandexConfig.Proxy,
|
||||
"baidu": config.BaiduConfig.Proxy,
|
||||
"bing": config.BingConfig.Proxy,
|
||||
"duckduckgo": config.DuckDuckGoConfig.Proxy,
|
||||
}
|
||||
}
|
||||
|
||||
func buildNormalizedProxyConfig(runtime string) (core.ProxyConfig, error) {
|
||||
return core.NormalizeProxyConfig(core.ProxyConfig{
|
||||
Runtime: runtime,
|
||||
Proxies: config.Proxies,
|
||||
EnginePolicies: buildEngineProxyPolicyMap(),
|
||||
})
|
||||
}
|
||||
|
||||
func resolveEngineProxyPolicy(proxyCfg core.ProxyConfig, engineName string) core.ProxyPolicy {
|
||||
engineKey := strings.ToLower(strings.TrimSpace(engineName))
|
||||
return core.ResolveEffectiveProxyPolicy(proxyCfg.Proxies.Global, proxyCfg.EnginePolicies[engineKey])
|
||||
}
|
||||
284
cmd/root.go
284
cmd/root.go
@@ -2,6 +2,8 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
@@ -12,38 +14,106 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
version = "0.3"
|
||||
version = "0.6.0"
|
||||
defaultConfigFilename = "config"
|
||||
envPrefix = "OPENSERP"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App AppConfig `mapstructure:"app"`
|
||||
Config2Capcha Config2Captcha `mapstructure:"2captcha"`
|
||||
GoogleConfig core.SearchEngineOptions `mapstructure:"google"`
|
||||
YandexConfig core.SearchEngineOptions `mapstructure:"yandex"`
|
||||
BaiduConfig core.SearchEngineOptions `mapstructure:"baidu"`
|
||||
Server ServerConfig `mapstructure:"server"`
|
||||
App AppConfig `mapstructure:"app"`
|
||||
Proxies core.ProxiesConfig `mapstructure:"proxies"`
|
||||
Cache CacheConfig `mapstructure:"cache"`
|
||||
Resilience ResilienceConfig `mapstructure:"resilience"`
|
||||
CircuitBreaker CircuitBreakerConfig `mapstructure:"circuit_breaker"`
|
||||
CORS CORSConfig `mapstructure:"cors"`
|
||||
Config2Capcha Config2Captcha `mapstructure:"2captcha"`
|
||||
GoogleConfig EngineConfig `mapstructure:"google"`
|
||||
YandexConfig EngineConfig `mapstructure:"yandex"`
|
||||
BaiduConfig EngineConfig `mapstructure:"baidu"`
|
||||
BingConfig EngineConfig `mapstructure:"bing"`
|
||||
DuckDuckGoConfig EngineConfig `mapstructure:"duckduckgo"`
|
||||
}
|
||||
|
||||
type Config2Captcha struct {
|
||||
ApiKey string `mapstructure:"apikey"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
type ServerConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"port"`
|
||||
Timeout int `mapstructure:"timeout"`
|
||||
ConfigPath string `mapstructure:"config_path"`
|
||||
IsBrowserHead bool `mapstructure:"head"`
|
||||
IsLeaveHead bool `mapstructure:"leave_head"`
|
||||
IsLeakless bool `mapstructure:"leakless"`
|
||||
IsDebug bool `mapstructure:"debug"`
|
||||
IsVerbose bool `mapstructure:"verbose"`
|
||||
IsRawRequests bool `mapstructure:"raw_requests"`
|
||||
Insecure bool `mapstructure:"insecure"`
|
||||
}
|
||||
|
||||
type AppConfig struct {
|
||||
Timeout int `mapstructure:"timeout"`
|
||||
BrowserPath string `mapstructure:"browser_path"`
|
||||
IsBrowserHead bool `mapstructure:"head"`
|
||||
IsLeaveHead bool `mapstructure:"leave_head"`
|
||||
IsLeakless bool `mapstructure:"leakless"`
|
||||
IsStealth bool `mapstructure:"stealth"`
|
||||
}
|
||||
|
||||
type EngineConfig struct {
|
||||
core.SearchEngineOptions `mapstructure:",squash"`
|
||||
Proxy string `mapstructure:"proxy"`
|
||||
}
|
||||
|
||||
type CacheConfig struct {
|
||||
TTLSeconds int `mapstructure:"ttl_seconds"`
|
||||
MaxSize int `mapstructure:"max_size"`
|
||||
}
|
||||
|
||||
type ResilienceConfig struct {
|
||||
MaxRetries int `mapstructure:"max_retries"`
|
||||
AllowEndpointFallback bool `mapstructure:"allow_endpoint_fallback"`
|
||||
}
|
||||
|
||||
type CircuitBreakerConfig struct {
|
||||
Failures int `mapstructure:"failures"`
|
||||
RecoverySeconds int `mapstructure:"recovery_seconds"`
|
||||
Successes int `mapstructure:"successes"`
|
||||
}
|
||||
|
||||
type CORSConfig struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
AllowOrigins string `mapstructure:"allow_origins"`
|
||||
AllowMethods string `mapstructure:"allow_methods"`
|
||||
AllowHeaders string `mapstructure:"allow_headers"`
|
||||
MaxAge int `mapstructure:"max_age"`
|
||||
}
|
||||
|
||||
var config = Config{}
|
||||
|
||||
var flagToConfigKey = map[string]string{
|
||||
"host": "server.host",
|
||||
"port": "server.port",
|
||||
"timeout": "app.timeout",
|
||||
"config": "server.config_path",
|
||||
"browser-path": "app.browser_path",
|
||||
"verbose": "server.verbose",
|
||||
"debug": "server.debug",
|
||||
"head": "app.head",
|
||||
"leakless": "app.leakless",
|
||||
"raw": "server.raw_requests",
|
||||
"leave": "app.leave_head",
|
||||
"2captcha_key": "2captcha.apikey",
|
||||
"proxy": "proxies.global",
|
||||
"stealth": "app.stealth",
|
||||
"insecure": "server.insecure",
|
||||
"cache_ttl": "cache.ttl_seconds",
|
||||
"cache_max_size": "cache.max_size",
|
||||
"max_retries": "resilience.max_retries",
|
||||
"allow_endpoint_fallback": "resilience.allow_endpoint_fallback",
|
||||
"cb_failures": "circuit_breaker.failures",
|
||||
"cb_recovery": "circuit_breaker.recovery_seconds",
|
||||
"cb_successes": "circuit_breaker.successes",
|
||||
}
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "openserp",
|
||||
Short: "Open SERP",
|
||||
@@ -51,52 +121,82 @@ var RootCmd = &cobra.Command{
|
||||
Version: version,
|
||||
SilenceUsage: true,
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
core.InitLogger(config.App.IsVerbose, config.App.IsDebug)
|
||||
|
||||
err := initializeConfig(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
core.InitLogger(config.Server.IsVerbose, config.Server.IsDebug)
|
||||
logrus.Debugf("Final config: %+v", config)
|
||||
return nil
|
||||
},
|
||||
|
||||
// Run: func(cmd *cobra.Command, args []string) {
|
||||
// // Working with OutOrStdout/OutOrStderr allows us to unit test our command easier
|
||||
// //out := cmd.OutOrStdout()
|
||||
// logrus.Trace("Config:", config)
|
||||
// },
|
||||
}
|
||||
|
||||
// Bind each cobra flag to its associated viper configuration (config file and environment variable)
|
||||
func bindFlags(cmd *cobra.Command, vpr *viper.Viper) {
|
||||
cmd.Flags().VisitAll(func(flg *pflag.Flag) {
|
||||
configName := "app." + flg.Name
|
||||
configName, ok := flagToConfigKey[flg.Name]
|
||||
if !ok {
|
||||
configName = "app." + flg.Name
|
||||
}
|
||||
|
||||
if err := vpr.BindPFlag(configName, flg); err != nil {
|
||||
logrus.Errorf("Unable to bind flag %s: %v", flg.Name, err)
|
||||
}
|
||||
|
||||
// Apply viper config value to the flag if viper has a value
|
||||
if flg.Changed {
|
||||
vpr.Set(configName, flg.Value)
|
||||
val, err := parseFlagValue(flg)
|
||||
if err != nil {
|
||||
logrus.Errorf("Unable to parse flag %s: %v", flg.Name, err)
|
||||
return
|
||||
}
|
||||
vpr.Set(configName, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func parseFlagValue(flg *pflag.Flag) (interface{}, error) {
|
||||
switch flg.Value.Type() {
|
||||
case "string":
|
||||
return flg.Value.String(), nil
|
||||
case "bool":
|
||||
return strconv.ParseBool(flg.Value.String())
|
||||
case "int":
|
||||
return strconv.Atoi(flg.Value.String())
|
||||
default:
|
||||
return flg.Value.String(), nil
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize Viper
|
||||
func initializeConfig(cmd *cobra.Command) error {
|
||||
v := viper.New()
|
||||
setConfigDefaults(v)
|
||||
|
||||
// Base name of the config file, without the file extension
|
||||
v.SetConfigName(defaultConfigFilename)
|
||||
v.AddConfigPath(".")
|
||||
explicitConfigPath := strings.TrimSpace(cmd.Flag("config").Value.String())
|
||||
if explicitConfigPath == "" {
|
||||
explicitConfigPath = strings.TrimSpace(os.Getenv(envPrefix + "_SERVER_CONFIG_PATH"))
|
||||
}
|
||||
|
||||
// 1. Config. Return an error if we cannot parse the config file.
|
||||
if explicitConfigPath != "" {
|
||||
v.SetConfigFile(explicitConfigPath)
|
||||
} else {
|
||||
// Base name of the config file, without the file extension
|
||||
v.SetConfigName(defaultConfigFilename)
|
||||
v.AddConfigPath(".")
|
||||
}
|
||||
|
||||
// 1. Config file (lowest priority). Return an error if we cannot parse the config file.
|
||||
err := v.ReadInConfig()
|
||||
if err != nil {
|
||||
if explicitConfigPath != "" {
|
||||
return fmt.Errorf("cannot read config %q: %w", explicitConfigPath, err)
|
||||
}
|
||||
err = fmt.Errorf("cannot read config: %v", err)
|
||||
logrus.Warn(err)
|
||||
}
|
||||
|
||||
// 2. Env. Bind environment variables to their equivalent keys with underscores
|
||||
// 2. Environment variables (medium priority). Bind environment variables to their equivalent keys with underscores
|
||||
for _, key := range v.AllKeys() {
|
||||
envKey := envPrefix + "_" + strings.ToUpper(strings.ReplaceAll(key, ".", "_"))
|
||||
err := v.BindEnv(key, envKey)
|
||||
@@ -105,32 +205,146 @@ func initializeConfig(cmd *cobra.Command) error {
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Cmd flags. Bind the current command's flags to viper
|
||||
// 3. Command flags (highest priority). Bind the current command's flags to viper
|
||||
bindFlags(cmd, v)
|
||||
|
||||
if err := validateRemovedConfigPaths(v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Dump Viper values to config struct
|
||||
if err := validateEngineProxyTags(v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = v.Unmarshal(&config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot unmarshall config: %v", err)
|
||||
}
|
||||
|
||||
if config.App.IsDebug {
|
||||
config.Proxies, err = core.NormalizeProxiesConfig(config.Proxies)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid proxies config: %w", err)
|
||||
}
|
||||
|
||||
if config.Server.IsDebug {
|
||||
logrus.Debug("Viper config:")
|
||||
v.Debug()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateEngineProxyTags(v *viper.Viper) error {
|
||||
for _, engineName := range []string{"google", "yandex", "baidu", "bing", "duckduckgo"} {
|
||||
key := engineName + ".proxy"
|
||||
if !v.IsSet(key) {
|
||||
continue
|
||||
}
|
||||
|
||||
raw := v.Get(key)
|
||||
tag, ok := raw.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid %s.proxy config: proxy must be a string tag", engineName)
|
||||
}
|
||||
|
||||
if _, err := core.NormalizeProxyTag(tag); err != nil {
|
||||
return fmt.Errorf("invalid %s.proxy config: %w", engineName, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRemovedConfigPaths(v *viper.Viper) error {
|
||||
legacyKeys := map[string]string{
|
||||
"app.proxy": "use proxies.global or proxies.entries with per-engine proxy tags instead",
|
||||
"proxy_pool": "use proxies.entries and proxies.health.failure_threshold instead",
|
||||
"proxy_pool.urls": "use proxies.entries instead",
|
||||
"proxy_pool.failure_threshold": "use proxies.health.failure_threshold instead",
|
||||
"app.host": "move to server.host",
|
||||
"app.port": "move to server.port",
|
||||
"app.debug": "move to server.debug",
|
||||
"app.verbose": "move to server.verbose",
|
||||
"app.raw_requests": "move to server.raw_requests",
|
||||
"app.insecure": "move to server.insecure",
|
||||
"proxies.defaults": "use proxies.global or per-engine proxy tags instead",
|
||||
"proxies.defaults.mode": "use proxies.global or per-engine proxy tags instead",
|
||||
"proxies.defaults.tag": "use per-engine proxy tags on each engine instead",
|
||||
"google.proxy.mode": "use google.proxy: <tag> or omit it for direct mode",
|
||||
"google.proxy.tag": "use google.proxy: <tag>",
|
||||
"yandex.proxy.mode": "use yandex.proxy: <tag> or omit it for direct mode",
|
||||
"yandex.proxy.tag": "use yandex.proxy: <tag>",
|
||||
"baidu.proxy.mode": "use baidu.proxy: <tag> or omit it for direct mode",
|
||||
"baidu.proxy.tag": "use baidu.proxy: <tag>",
|
||||
"bing.proxy.mode": "use bing.proxy: <tag> or omit it for direct mode",
|
||||
"bing.proxy.tag": "use bing.proxy: <tag>",
|
||||
"duckduckgo.proxy.mode": "use duckduckgo.proxy: <tag> or omit it for direct mode",
|
||||
"duckduckgo.proxy.tag": "use duckduckgo.proxy: <tag>",
|
||||
}
|
||||
|
||||
for key, hint := range legacyKeys {
|
||||
if v.IsSet(key) {
|
||||
return fmt.Errorf("config key %q is removed in proxy v2: %s", key, hint)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setConfigDefaults(v *viper.Viper) {
|
||||
v.SetDefault("server.host", "127.0.0.1")
|
||||
v.SetDefault("server.port", 7070)
|
||||
v.SetDefault("server.debug", false)
|
||||
v.SetDefault("server.verbose", false)
|
||||
v.SetDefault("server.raw_requests", false)
|
||||
v.SetDefault("server.insecure", false)
|
||||
|
||||
v.SetDefault("app.timeout", 30)
|
||||
v.SetDefault("app.browser_path", "")
|
||||
v.SetDefault("app.head", false)
|
||||
v.SetDefault("app.leave_head", false)
|
||||
v.SetDefault("app.leakless", false)
|
||||
v.SetDefault("app.stealth", false)
|
||||
|
||||
v.SetDefault("proxies.entries", []interface{}{})
|
||||
v.SetDefault("proxies.global", "")
|
||||
v.SetDefault("proxies.health.failure_threshold", core.DefaultProxyFailureThreshold)
|
||||
|
||||
v.SetDefault("cache.ttl_seconds", 300)
|
||||
v.SetDefault("cache.max_size", 1000)
|
||||
// Keep stage2 defaults stable even when config file is absent.
|
||||
v.SetDefault("resilience.max_retries", 3)
|
||||
v.SetDefault("resilience.allow_endpoint_fallback", false)
|
||||
v.SetDefault("circuit_breaker.failures", 5)
|
||||
v.SetDefault("circuit_breaker.recovery_seconds", 60)
|
||||
v.SetDefault("circuit_breaker.successes", 2)
|
||||
v.SetDefault("cors.enabled", true)
|
||||
v.SetDefault("cors.allow_origins", "*")
|
||||
v.SetDefault("cors.allow_methods", "GET, POST, OPTIONS")
|
||||
v.SetDefault("cors.allow_headers", "Origin, Content-Type, Accept, Authorization, X-Use-Proxy")
|
||||
v.SetDefault("cors.max_age", 86400)
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.PersistentFlags().IntVarP(&config.App.Port, "port", "p", 7070, "Port number to run server")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.App.Host, "host", "a", "127.0.0.1", "Host address to run server")
|
||||
RootCmd.PersistentFlags().IntVarP(&config.Server.Port, "port", "p", 7070, "Port number to run server")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.Server.Host, "host", "a", "127.0.0.1", "Host address to run server")
|
||||
RootCmd.PersistentFlags().IntVarP(&config.App.Timeout, "timeout", "t", 30, "Timeout to fail request")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.App.ConfigPath, "config", "c", "", "Configuration file path")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsVerbose, "verbose", "v", false, "Use verbose output")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsDebug, "debug", "d", false, "Use debug output. Disable headless browser")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.Server.ConfigPath, "config", "c", "", "Configuration file path")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.App.BrowserPath, "browser-path", "", "", "Custom browser binary path (Chrome/Chromium/Edge/Brave..)")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.Server.IsVerbose, "verbose", "v", false, "Use verbose output")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.Server.IsDebug, "debug", "d", false, "Use debug output. Disable headless browser")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsBrowserHead, "head", "", false, "Enable browser UI")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsLeakless, "leakless", "l", false, "Use leakless mode to insure browser instances are closed after search")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsRawRequests, "raw", "r", false, "Disable browser usage, use HTTP requests")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.Server.IsRawRequests, "raw", "r", false, "Disable browser usage, use HTTP requests")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsLeaveHead, "leave", "", false, "Leave browser and tabs opened after search is made")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.Config2Capcha.ApiKey, "2captcha_key", "", "", "2 captcha api key")
|
||||
RootCmd.PersistentFlags().StringVarP(&config.Proxies.Global, "proxy", "x", "", "Force a single proxy for all engines (same as proxies.global)")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.App.IsStealth, "stealth", "s", false, "Use stealth browser plugin")
|
||||
RootCmd.PersistentFlags().BoolVarP(&config.Server.Insecure, "insecure", "k", false, "Allow insecure TLS connections")
|
||||
RootCmd.PersistentFlags().IntVar(&config.Cache.TTLSeconds, "cache_ttl", 300, "Cache TTL in seconds (0 to disable)")
|
||||
RootCmd.PersistentFlags().IntVar(&config.Cache.MaxSize, "cache_max_size", 1000, "Maximum number of cached responses")
|
||||
RootCmd.PersistentFlags().IntVar(&config.Resilience.MaxRetries, "max_retries", 3, "Max retry attempts per search engine (0 to disable)")
|
||||
RootCmd.PersistentFlags().BoolVar(&config.Resilience.AllowEndpointFallback, "allow_endpoint_fallback", false, "Allow dedicated endpoints to fallback to other engines")
|
||||
RootCmd.PersistentFlags().IntVar(&config.CircuitBreaker.Failures, "cb_failures", 5, "Consecutive failures before circuit breaker opens")
|
||||
RootCmd.PersistentFlags().IntVar(&config.CircuitBreaker.RecoverySeconds, "cb_recovery", 60, "Seconds before retrying an engine with open circuit")
|
||||
RootCmd.PersistentFlags().IntVar(&config.CircuitBreaker.Successes, "cb_successes", 2, "Consecutive successful half-open checks needed to close circuit")
|
||||
}
|
||||
|
||||
121
cmd/search.go
121
cmd/search.go
@@ -7,7 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/baidu"
|
||||
"github.com/karust/openserp/bing"
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/karust/openserp/duckduckgo"
|
||||
"github.com/karust/openserp/google"
|
||||
"github.com/karust/openserp/yandex"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -17,31 +19,61 @@ import (
|
||||
var searchCMD = &cobra.Command{
|
||||
Use: "search",
|
||||
Aliases: []string{"find"},
|
||||
Short: "Search results using chosen web search engine (google, yandex, baidu)",
|
||||
Short: "Search results using chosen web search engine (google, yandex, baidu, bing, duckduckgo)",
|
||||
Args: cobra.MatchAll(cobra.OnlyValidArgs, cobra.ExactArgs(2)),
|
||||
Run: search,
|
||||
}
|
||||
|
||||
func search(cmd *cobra.Command, args []string) {
|
||||
var err error
|
||||
engineType := args[0]
|
||||
engineType := normalizeEngineArg(args[0])
|
||||
query := core.Query{
|
||||
Text: args[1],
|
||||
Limit: 10,
|
||||
Text: args[1],
|
||||
Limit: 10,
|
||||
Filter: true,
|
||||
Insecure: config.Server.Insecure,
|
||||
}
|
||||
results := []core.SearchResult{}
|
||||
|
||||
if config.App.IsRawRequests {
|
||||
proxyRuntime := core.ProxyRuntimeBrowser
|
||||
if config.Server.IsRawRequests {
|
||||
proxyRuntime = core.ProxyRuntimeRaw
|
||||
}
|
||||
|
||||
proxyCfg, err := buildNormalizedProxyConfig(proxyRuntime)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error validating proxy config: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
policy := resolveEngineProxyPolicy(proxyCfg, engineType)
|
||||
|
||||
selectedProxy, err := selectCLIProxy(proxyCfg, policy)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error selecting proxy for %s: %v", engineType, err)
|
||||
return
|
||||
}
|
||||
|
||||
if config.Server.IsRawRequests {
|
||||
query.ProxyURL = selectedProxy
|
||||
}
|
||||
|
||||
logrus.Infof("Starting SERP search request using %s engine for query: %s", engineType, query.Text)
|
||||
|
||||
var results []core.SearchResult
|
||||
if config.Server.IsRawRequests {
|
||||
logrus.Infof("Using raw requests mode for %s search", engineType)
|
||||
results, err = searchRaw(engineType, query)
|
||||
} else {
|
||||
results, err = searchBrowser(engineType, query)
|
||||
logrus.Infof("Using browser mode for %s search", engineType)
|
||||
results, err = searchBrowser(engineType, query, selectedProxy)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
logrus.Errorf("Error during %s search: %s", engineType, err)
|
||||
return
|
||||
}
|
||||
|
||||
logrus.Infof("Successfully completed SERP search using %s engine, returned %d results", engineType, len(results))
|
||||
|
||||
b, err := json.MarshalIndent(results, "", " ")
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
@@ -50,35 +82,51 @@ func search(cmd *cobra.Command, args []string) {
|
||||
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
func searchBrowser(engineType string, query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
func searchBrowser(engineType string, query core.Query, browserProxyURL string) ([]core.SearchResult, error) {
|
||||
var engine core.SearchEngine
|
||||
if core.IsAuthenticatedSocksProxyURL(browserProxyURL) {
|
||||
return nil, fmt.Errorf(
|
||||
"%w: browser runtime does not support authenticated SOCKS proxy %s",
|
||||
core.ErrProxyUnavailable,
|
||||
core.MaskProxyURL(browserProxyURL),
|
||||
)
|
||||
}
|
||||
|
||||
opts := core.BrowserOpts{
|
||||
IsHeadless: !config.App.IsBrowserHead, // Disable headless if browser head mode is set
|
||||
IsHeadless: !config.App.IsBrowserHead,
|
||||
IsLeakless: config.App.IsLeakless,
|
||||
Timeout: time.Second * time.Duration(config.App.Timeout),
|
||||
LeavePageOpen: config.App.IsLeaveHead,
|
||||
CaptchaSolverApiKey: config.Config2Capcha.ApiKey,
|
||||
BrowserPath: config.App.BrowserPath,
|
||||
ProxyURL: browserProxyURL,
|
||||
Insecure: config.Server.Insecure,
|
||||
UseStealth: config.App.IsStealth,
|
||||
}
|
||||
|
||||
if config.App.IsDebug {
|
||||
if config.Server.IsDebug {
|
||||
opts.IsHeadless = false
|
||||
}
|
||||
|
||||
browser, err := core.NewBrowser(opts)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch strings.ToLower(engineType) {
|
||||
case "yandex":
|
||||
engine = yandex.New(*browser, config.YandexConfig)
|
||||
engine = yandex.New(*browser, config.YandexConfig.SearchEngineOptions)
|
||||
case "google":
|
||||
engine = google.New(*browser, config.GoogleConfig)
|
||||
engine = google.New(*browser, config.GoogleConfig.SearchEngineOptions)
|
||||
case "baidu":
|
||||
engine = baidu.New(*browser, config.BaiduConfig)
|
||||
engine = baidu.New(*browser, config.BaiduConfig.SearchEngineOptions)
|
||||
case "bing":
|
||||
engine = bing.New(*browser, config.BingConfig.SearchEngineOptions)
|
||||
case "duckduckgo":
|
||||
engine = duckduckgo.New(*browser, config.DuckDuckGoConfig.SearchEngineOptions)
|
||||
default:
|
||||
logrus.Infof("No `%s` search engine found", engineType)
|
||||
return nil, fmt.Errorf("no %q search engine found", engineType)
|
||||
}
|
||||
|
||||
return engine.Search(query)
|
||||
@@ -94,10 +142,45 @@ func searchRaw(engineType string, query core.Query) ([]core.SearchResult, error)
|
||||
return google.Search(query)
|
||||
case "baidu":
|
||||
return baidu.Search(query)
|
||||
case "bing":
|
||||
logrus.Warn("Bing does not support raw HTTP requests mode. Please use browser mode instead.")
|
||||
return nil, fmt.Errorf("bing does not support raw requests mode")
|
||||
case "duckduckgo":
|
||||
logrus.Warn("DuckDuckGo does not support raw HTTP requests mode. Please use browser mode instead.")
|
||||
return nil, fmt.Errorf("duckduckgo does not support raw requests mode")
|
||||
default:
|
||||
logrus.Infof("No `%s` search engine found", engineType)
|
||||
return nil, fmt.Errorf("no %q search engine found", engineType)
|
||||
}
|
||||
}
|
||||
|
||||
func selectCLIProxy(proxyCfg core.ProxyConfig, policy core.ProxyPolicy) (string, error) {
|
||||
if policy.Mode == core.ProxyModeOff {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
if global := strings.TrimSpace(proxyCfg.Proxies.Global); global != "" {
|
||||
return global, nil
|
||||
}
|
||||
|
||||
if proxyCfg.Registry == nil {
|
||||
return "", fmt.Errorf("%w: no proxy registry configured", core.ErrProxyUnavailable)
|
||||
}
|
||||
|
||||
selected := proxyCfg.Registry.NextByTag(policy.Tag)
|
||||
if selected == "" {
|
||||
return "", fmt.Errorf("%w: no healthy proxy available for tag %q", core.ErrProxyUnavailable, policy.Tag)
|
||||
}
|
||||
|
||||
return selected, nil
|
||||
}
|
||||
|
||||
func normalizeEngineArg(raw string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(raw)) {
|
||||
case "duck":
|
||||
return "duckduckgo"
|
||||
default:
|
||||
return strings.ToLower(strings.TrimSpace(raw))
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
345
cmd/serve.go
345
cmd/serve.go
@@ -1,16 +1,59 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/baidu"
|
||||
"github.com/karust/openserp/bing"
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/karust/openserp/duckduckgo"
|
||||
"github.com/karust/openserp/google"
|
||||
"github.com/karust/openserp/yandex"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
// rawEngine implements SearchEngine interface for raw HTTP requests
|
||||
type rawEngine struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (r *rawEngine) Search(q core.Query) ([]core.SearchResult, error) {
|
||||
q.Insecure = config.Server.Insecure
|
||||
|
||||
switch r.name {
|
||||
case "google":
|
||||
return google.Search(q)
|
||||
case "yandex":
|
||||
return yandex.Search(q)
|
||||
case "baidu":
|
||||
return baidu.Search(q)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported engine: %s", r.name)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rawEngine) SearchImage(q core.Query) ([]core.SearchResult, error) {
|
||||
return nil, fmt.Errorf("image search is not supported in raw mode for %s", r.name)
|
||||
}
|
||||
|
||||
func (r *rawEngine) Name() string {
|
||||
return r.name
|
||||
}
|
||||
|
||||
func (r *rawEngine) IsInitialized() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *rawEngine) GetRateLimiter() *rate.Limiter {
|
||||
// Use default rate limiter for raw requests
|
||||
return rate.NewLimiter(rate.Every(time.Second), 5)
|
||||
}
|
||||
|
||||
var serveCMD = &cobra.Command{
|
||||
Use: "serve",
|
||||
Aliases: []string{"listen"},
|
||||
@@ -20,29 +63,307 @@ var serveCMD = &cobra.Command{
|
||||
}
|
||||
|
||||
func serve(cmd *cobra.Command, args []string) {
|
||||
opts := core.BrowserOpts{
|
||||
IsHeadless: !config.App.IsBrowserHead, // Disable headless if browser head mode is set
|
||||
corsCfg := core.DefaultCORSConfig()
|
||||
corsCfg.AllowOrigins = config.CORS.AllowOrigins
|
||||
corsCfg.AllowMethods = config.CORS.AllowMethods
|
||||
corsCfg.AllowHeaders = config.CORS.AllowHeaders
|
||||
corsCfg.MaxAge = config.CORS.MaxAge
|
||||
|
||||
proxyRuntime := core.ProxyRuntimeBrowser
|
||||
if config.Server.IsRawRequests {
|
||||
proxyRuntime = core.ProxyRuntimeRaw
|
||||
}
|
||||
|
||||
proxyCfg, err := buildNormalizedProxyConfig(proxyRuntime)
|
||||
if err != nil {
|
||||
logrus.Errorf("invalid proxy configuration: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if config.Server.IsRawRequests {
|
||||
logrus.Warn("Browserless results are very inconsistent or may not even work!")
|
||||
serverOpts := buildServerOptions(corsCfg, proxyCfg)
|
||||
serv := core.NewServerWithOptions(config.Server.Host, config.Server.Port, serverOpts,
|
||||
&rawEngine{name: "google"},
|
||||
&rawEngine{name: "yandex"},
|
||||
&rawEngine{name: "baidu"},
|
||||
)
|
||||
if err := serv.Listen(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
baseOpts := core.BrowserOpts{
|
||||
IsHeadless: !config.App.IsBrowserHead,
|
||||
IsLeakless: config.App.IsLeakless,
|
||||
Timeout: time.Second * time.Duration(config.App.Timeout),
|
||||
LeavePageOpen: config.App.IsLeaveHead,
|
||||
CaptchaSolverApiKey: config.Config2Capcha.ApiKey,
|
||||
BrowserPath: config.App.BrowserPath,
|
||||
Insecure: config.Server.Insecure,
|
||||
UseStealth: config.App.IsStealth,
|
||||
}
|
||||
if config.Server.IsDebug {
|
||||
baseOpts.IsHeadless = false
|
||||
}
|
||||
|
||||
if config.App.IsDebug {
|
||||
opts.IsHeadless = false
|
||||
}
|
||||
|
||||
browser, err := core.NewBrowser(opts)
|
||||
engines, err := buildBrowserEngines(baseOpts, proxyCfg)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
yand := yandex.New(*browser, config.YandexConfig)
|
||||
gogl := google.New(*browser, config.GoogleConfig)
|
||||
baidu := baidu.New(*browser, config.BaiduConfig)
|
||||
serverOpts := buildServerOptions(corsCfg, proxyCfg)
|
||||
serv := core.NewServerWithOptions(config.Server.Host, config.Server.Port, serverOpts, engines...)
|
||||
if err := serv.Listen(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
serv := core.NewServer(config.App.Host, config.App.Port, gogl, yand, baidu)
|
||||
serv.Listen()
|
||||
func buildServerOptions(corsCfg core.CORSConfig, proxyCfg core.ProxyConfig) core.ServerOptions {
|
||||
return core.ServerOptions{
|
||||
CacheTTL: time.Duration(config.Cache.TTLSeconds) * time.Second,
|
||||
CacheMaxSize: config.Cache.MaxSize,
|
||||
EnableCORS: config.CORS.Enabled,
|
||||
CORS: corsCfg,
|
||||
AllowEndpointFallback: config.Resilience.AllowEndpointFallback,
|
||||
Resilience: core.ResilientConfig{
|
||||
Retry: core.RetryConfig{
|
||||
MaxRetries: config.Resilience.MaxRetries,
|
||||
InitialBackoff: 1 * time.Second,
|
||||
MaxBackoff: 30 * time.Second,
|
||||
BackoffFactor: 2.0,
|
||||
},
|
||||
CircuitBreaker: core.CircuitBreakerConfig{
|
||||
FailureThreshold: config.CircuitBreaker.Failures,
|
||||
RecoveryTimeout: time.Duration(config.CircuitBreaker.RecoverySeconds) * time.Second,
|
||||
SuccessThreshold: config.CircuitBreaker.Successes,
|
||||
},
|
||||
Proxy: proxyCfg,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type browserPool struct {
|
||||
mu sync.Mutex
|
||||
base core.BrowserOpts
|
||||
browser map[string]*core.Browser
|
||||
}
|
||||
|
||||
func newBrowserPool(base core.BrowserOpts) *browserPool {
|
||||
return &browserPool{
|
||||
base: base,
|
||||
browser: map[string]*core.Browser{},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *browserPool) get(proxyURL string) (*core.Browser, error) {
|
||||
key := strings.TrimSpace(proxyURL)
|
||||
if key == "" {
|
||||
key = "direct"
|
||||
}
|
||||
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if b, ok := p.browser[key]; ok {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
opts := p.base
|
||||
opts.ProxyURL = proxyURL
|
||||
b, err := core.NewBrowser(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Reuse one launched browser per unique effective proxy so startup stays lazy
|
||||
// and engines with identical proxy policy don't spawn duplicate browser processes.
|
||||
p.browser[key] = b
|
||||
return b, nil
|
||||
}
|
||||
|
||||
type pooledBrowserEngine struct {
|
||||
name string
|
||||
limiter *rate.Limiter
|
||||
opts core.SearchEngineOptions
|
||||
factory func(core.Browser, core.SearchEngineOptions) core.SearchEngine
|
||||
pool *browserPool
|
||||
|
||||
mu sync.Mutex
|
||||
engines map[string]core.SearchEngine
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) Search(q core.Query) ([]core.SearchResult, error) {
|
||||
engine, err := e.getOrCreate(q.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine.Search(q)
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) SearchImage(q core.Query) ([]core.SearchResult, error) {
|
||||
engine, err := e.getOrCreate(q.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine.SearchImage(q)
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) IsInitialized() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) Name() string {
|
||||
return e.name
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) GetRateLimiter() *rate.Limiter {
|
||||
return e.limiter
|
||||
}
|
||||
|
||||
func (e *pooledBrowserEngine) getOrCreate(proxyURL string) (core.SearchEngine, error) {
|
||||
key := strings.TrimSpace(proxyURL)
|
||||
if key == "" {
|
||||
key = "direct"
|
||||
}
|
||||
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
if engine, ok := e.engines[key]; ok {
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
browser, err := e.pool.get(proxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
engine := e.factory(*browser, e.opts)
|
||||
e.engines[key] = engine
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
type browserEngineSpec struct {
|
||||
name string
|
||||
opts core.SearchEngineOptions
|
||||
factory func(core.Browser, core.SearchEngineOptions) core.SearchEngine
|
||||
}
|
||||
|
||||
func browserEngineSpecs() []browserEngineSpec {
|
||||
return []browserEngineSpec{
|
||||
{
|
||||
name: "google",
|
||||
opts: config.GoogleConfig.SearchEngineOptions,
|
||||
factory: func(browser core.Browser, opts core.SearchEngineOptions) core.SearchEngine {
|
||||
return google.New(browser, opts)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "yandex",
|
||||
opts: config.YandexConfig.SearchEngineOptions,
|
||||
factory: func(browser core.Browser, opts core.SearchEngineOptions) core.SearchEngine {
|
||||
return yandex.New(browser, opts)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "baidu",
|
||||
opts: config.BaiduConfig.SearchEngineOptions,
|
||||
factory: func(browser core.Browser, opts core.SearchEngineOptions) core.SearchEngine {
|
||||
return baidu.New(browser, opts)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bing",
|
||||
opts: config.BingConfig.SearchEngineOptions,
|
||||
factory: func(browser core.Browser, opts core.SearchEngineOptions) core.SearchEngine {
|
||||
return bing.New(browser, opts)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duckduckgo",
|
||||
opts: config.DuckDuckGoConfig.SearchEngineOptions,
|
||||
factory: func(browser core.Browser, opts core.SearchEngineOptions) core.SearchEngine {
|
||||
return duckduckgo.New(browser, opts)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func buildBrowserEngines(baseOpts core.BrowserOpts, proxyCfg core.ProxyConfig) ([]core.SearchEngine, error) {
|
||||
pool := newBrowserPool(baseOpts)
|
||||
specs := browserEngineSpecs()
|
||||
|
||||
engines := make([]core.SearchEngine, 0, len(specs))
|
||||
for _, spec := range specs {
|
||||
policy := resolveEngineProxyPolicy(proxyCfg, spec.name)
|
||||
if err := validateBrowserProxyPolicy(proxyCfg, policy); err != nil {
|
||||
return nil, fmt.Errorf("browser proxy validation failed for engine %s: %w", spec.name, err)
|
||||
}
|
||||
|
||||
opts := spec.opts
|
||||
opts.Init()
|
||||
engines = append(engines, &pooledBrowserEngine{
|
||||
name: spec.name,
|
||||
limiter: rate.NewLimiter(rate.Every(opts.GetRatelimit()), opts.RateBurst),
|
||||
opts: opts,
|
||||
factory: spec.factory,
|
||||
pool: pool,
|
||||
engines: map[string]core.SearchEngine{},
|
||||
})
|
||||
}
|
||||
|
||||
return engines, nil
|
||||
}
|
||||
|
||||
func validateBrowserProxyPolicy(proxyCfg core.ProxyConfig, policy core.ProxyPolicy) error {
|
||||
if policy.Mode != core.ProxyModeTagPool {
|
||||
return nil
|
||||
}
|
||||
|
||||
proxyURL := strings.TrimSpace(proxyCfg.Proxies.Global)
|
||||
if proxyURL != "" {
|
||||
return validateBrowserProxyURL(proxyURL)
|
||||
}
|
||||
|
||||
for _, entry := range proxyCfg.Proxies.Entries {
|
||||
if !entryHasTag(entry, policy.Tag) {
|
||||
continue
|
||||
}
|
||||
if err := validateBrowserProxyURL(entry.URL); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBrowserProxyURL(proxyURL string) error {
|
||||
// Browser startup must stop immediately on authenticated SOCKS because Chrome
|
||||
// cannot use that proxy shape reliably and retrying a different proxy hides the misconfiguration.
|
||||
if core.IsAuthenticatedSocksProxyURL(proxyURL) {
|
||||
return fmt.Errorf(
|
||||
"%w: browser runtime does not support authenticated SOCKS proxy %s",
|
||||
core.ErrProxyUnavailable,
|
||||
core.MaskProxyURL(proxyURL),
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func entryHasTag(entry core.ProxyEntryConfig, tag string) bool {
|
||||
tag = strings.TrimSpace(strings.ToLower(tag))
|
||||
if tag == "" {
|
||||
return false
|
||||
}
|
||||
for _, entryTag := range entry.Tags {
|
||||
if strings.TrimSpace(strings.ToLower(entryTag)) == tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
105
cmd/serve_test.go
Normal file
105
cmd/serve_test.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
func TestValidateBrowserProxyPolicyRejectsAuthenticatedSocks(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
proxyCfg core.ProxyConfig
|
||||
policy core.ProxyPolicy
|
||||
}{
|
||||
{
|
||||
name: "global authenticated socks",
|
||||
proxyCfg: core.ProxyConfig{
|
||||
Proxies: core.ProxiesConfig{
|
||||
Global: "socks5h://user:pass@127.0.0.1:1080",
|
||||
},
|
||||
},
|
||||
policy: core.ProxyPolicy{Mode: core.ProxyModeTagPool},
|
||||
},
|
||||
{
|
||||
name: "tag pool authenticated socks",
|
||||
proxyCfg: core.ProxyConfig{
|
||||
Proxies: core.ProxiesConfig{
|
||||
Entries: []core.ProxyEntryConfig{
|
||||
{URL: "socks5://user:pass@127.0.0.1:1080", Tags: []string{"us"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
policy: core.ProxyPolicy{Mode: core.ProxyModeTagPool, Tag: "us"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validateBrowserProxyPolicy(tt.proxyCfg, tt.policy)
|
||||
if err == nil {
|
||||
t.Fatal("expected browser proxy validation to fail")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "authenticated SOCKS proxy") {
|
||||
t.Fatalf("expected explicit authenticated SOCKS error, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBrowserProxyPolicyAllowsHTTPAuthAndPlainSocks(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
proxyCfg core.ProxyConfig
|
||||
policy core.ProxyPolicy
|
||||
}{
|
||||
{
|
||||
name: "global http auth",
|
||||
proxyCfg: core.ProxyConfig{
|
||||
Proxies: core.ProxiesConfig{
|
||||
Global: "http://user:pass@127.0.0.1:8080",
|
||||
},
|
||||
},
|
||||
policy: core.ProxyPolicy{Mode: core.ProxyModeTagPool},
|
||||
},
|
||||
{
|
||||
name: "tag pool plain socks",
|
||||
proxyCfg: core.ProxyConfig{
|
||||
Proxies: core.ProxiesConfig{
|
||||
Entries: []core.ProxyEntryConfig{
|
||||
{URL: "socks5://127.0.0.1:1080", Tags: []string{"eu"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
policy: core.ProxyPolicy{Mode: core.ProxyModeTagPool, Tag: "eu"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := validateBrowserProxyPolicy(tt.proxyCfg, tt.policy); err != nil {
|
||||
t.Fatalf("expected browser proxy validation to succeed, got %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBrowserProxyPolicyRejectsTaggedAuthenticatedSocksInPool(t *testing.T) {
|
||||
proxyCfg := core.ProxyConfig{
|
||||
Proxies: core.ProxiesConfig{
|
||||
Entries: []core.ProxyEntryConfig{
|
||||
{URL: "http://127.0.0.1:8080", Tags: []string{"default"}},
|
||||
{URL: "socks5://user:pass@127.0.0.1:1080", Tags: []string{"default"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := validateBrowserProxyPolicy(proxyCfg, core.ProxyPolicy{Mode: core.ProxyModeTagPool, Tag: "default"})
|
||||
if err == nil {
|
||||
t.Fatal("expected browser proxy validation to fail for tag pool")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "authenticated SOCKS proxy") {
|
||||
t.Fatalf("expected explicit authenticated SOCKS error, got %v", err)
|
||||
}
|
||||
}
|
||||
78
config.yaml
78
config.yaml
@@ -1,20 +1,60 @@
|
||||
app:
|
||||
host: 0.0.0.0
|
||||
port: 7000
|
||||
debug: false
|
||||
verbose: true
|
||||
timeout: 15
|
||||
head: false
|
||||
leakless: false
|
||||
leave_head: false
|
||||
server:
|
||||
host: 0.0.0.0 # API host to bind
|
||||
port: 7000 # API port to bind
|
||||
debug: false # Enable debug logs and force browser UI mode
|
||||
verbose: true # Enable info-level request logs
|
||||
raw_requests: false # true = raw HTTP mode, false = browser mode
|
||||
insecure: true # Allow insecure TLS connections
|
||||
|
||||
2captcha:
|
||||
apikey: "123123123123123"
|
||||
app:
|
||||
timeout: 15 # Browser/search timeout in seconds
|
||||
browser_path: "" # Custom browser binary path (chrome/chromium/edge..)
|
||||
head: false # Show browser UI (headful mode)
|
||||
leakless: false # Force browser process cleanup after request
|
||||
leave_head: false # Keep tabs open after request for debugging
|
||||
stealth: false # Enable stealth browser plugin
|
||||
|
||||
proxies:
|
||||
# Force a single proxy for all engines.
|
||||
# Same behavior as passing --proxy on the CLI.
|
||||
#global: http://127.0.0.1:8080
|
||||
|
||||
# Advanced mode: define tagged proxy pools and opt engines in with `proxy: <tag>`.
|
||||
#entries:
|
||||
# - url: http://127.0.0.1:8080
|
||||
# tags: [default, us]
|
||||
# - url: socks5h://127.0.0.1:1080
|
||||
# tags: [eu]
|
||||
health:
|
||||
failure_threshold: 3 # Disable proxy after this many consecutive failures
|
||||
|
||||
cache:
|
||||
ttl_seconds: 60 # Dedicated endpoint cache TTL in seconds (0 disables cache)
|
||||
max_size: 1000 # Maximum cached dedicated responses before oldest-entry eviction
|
||||
|
||||
resilience:
|
||||
max_retries: 2 # Retry attempts per engine request (0 disables retries)
|
||||
allow_endpoint_fallback: false # Keep dedicated endpoints engine-pure by default
|
||||
|
||||
# circuit_breaker:
|
||||
# failures: 5 # Consecutive failures required to open circuit
|
||||
# recovery_seconds: 60 # Wait time before moving open circuit to half-open
|
||||
# successes: 2 # Consecutive half-open successes required to close circuit
|
||||
|
||||
cors:
|
||||
enabled: true
|
||||
allow_origins: "*"
|
||||
allow_methods: "GET, POST, OPTIONS"
|
||||
allow_headers: "Origin, Content-Type, Accept, Authorization, X-Use-Proxy"
|
||||
max_age: 86400
|
||||
|
||||
# 2captcha:
|
||||
# apikey: "123123123123123"
|
||||
|
||||
google:
|
||||
rate_requests: 4 # Number of requests per Minute
|
||||
rate_burst: 2 # Number of non-ratelimited requests per Minute
|
||||
captcha: true
|
||||
rate_requests: 4 # Allowed average requests per minute
|
||||
rate_burst: 2 # Burst requests before limiter applies
|
||||
captcha: true # Enable captcha solver path
|
||||
|
||||
yandex:
|
||||
rate_requests: 4
|
||||
@@ -23,3 +63,13 @@ yandex:
|
||||
baidu:
|
||||
rate_requests: 4
|
||||
rate_burst: 2
|
||||
# No proxy tag means direct traffic
|
||||
|
||||
bing:
|
||||
rate_requests: 4
|
||||
rate_burst: 2
|
||||
# No proxy tag means direct traffic
|
||||
|
||||
duckduckgo:
|
||||
rate_requests: 4
|
||||
rate_burst: 2
|
||||
|
||||
224
core/browser.go
224
core/browser.go
@@ -1,11 +1,18 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/go-rod/rod/lib/devices"
|
||||
"github.com/go-rod/rod/lib/launcher"
|
||||
"github.com/go-rod/rod/lib/proto"
|
||||
"github.com/go-rod/stealth"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -19,6 +26,10 @@ type BrowserOpts struct {
|
||||
LeavePageOpen bool // Leave pages and browser open
|
||||
WaitLoadTime time.Duration // Time to wait till page loads
|
||||
CaptchaSolverApiKey string // 2Captcha api key
|
||||
BrowserPath string // Explicit browser executable path
|
||||
ProxyURL string // Proxy URL
|
||||
Insecure bool // Allow insecure TLS connections
|
||||
UseStealth bool // Use go-rod stealth plugin
|
||||
|
||||
}
|
||||
|
||||
@@ -44,12 +55,47 @@ func NewBrowser(opts BrowserOpts) (*Browser, error) {
|
||||
opts.Check()
|
||||
logrus.Debugf("Browser options: %+v", opts)
|
||||
|
||||
path, has := launcher.LookPath()
|
||||
logrus.Debug("Browser found: ", has)
|
||||
path, err := resolveBrowserBinaryPath(opts.BrowserPath, launcher.LookPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create launcher
|
||||
l := launcher.New().Leakless(opts.IsLeakless).Headless(opts.IsHeadless).Set("disable-blink-features", "AutomationControlled").
|
||||
Delete("enable-automation")
|
||||
if path != "" {
|
||||
logrus.Debugf("Using browser binary: %s", path)
|
||||
l = l.Bin(path)
|
||||
}
|
||||
|
||||
// Configure proxy if specified
|
||||
if opts.ProxyURL != "" {
|
||||
normalizedProxyURL, err := NormalizeProxyURL(opts.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid proxy URL: %v", err)
|
||||
}
|
||||
opts.ProxyURL = normalizedProxyURL
|
||||
|
||||
proxyUrl, err := url.Parse(opts.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid proxy URL: %v", err)
|
||||
}
|
||||
|
||||
// Chrome's proxy-server flag must not contain credentials.
|
||||
// Auth (if needed) is handled separately via DevTools auth callbacks.
|
||||
proxyStr := proxyURLForBrowserLaunch(proxyUrl)
|
||||
logrus.Debugf("Setting up proxy: %s", MaskProxyURL(proxyStr))
|
||||
l = l.Proxy(proxyStr)
|
||||
|
||||
// Check if proxy has auth credentials
|
||||
if proxyUrl.User != nil {
|
||||
username := proxyUrl.User.Username()
|
||||
logrus.Debugf("Proxy credentials configured for %s proxy: %s:****", proxyUrl.Scheme, username)
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
b := Browser{BrowserOpts: opts}
|
||||
b.browserAddr, err = launcher.New().Bin(path).Leakless(opts.IsLeakless).Headless(opts.IsHeadless).Launch()
|
||||
b.browserAddr, err = l.Launch()
|
||||
|
||||
if opts.CaptchaSolverApiKey != "" {
|
||||
b.CaptchaSolver = NewSolver(opts.CaptchaSolverApiKey)
|
||||
@@ -59,6 +105,52 @@ func NewBrowser(opts BrowserOpts) (*Browser, error) {
|
||||
return &b, err
|
||||
}
|
||||
|
||||
func proxyURLForBrowserLaunch(u *url.URL) string {
|
||||
if u == nil {
|
||||
return ""
|
||||
}
|
||||
clone := *u
|
||||
// Chrome expects socks5 scheme in --proxy-server; socks5h is not accepted.
|
||||
if clone.Scheme == "socks5h" {
|
||||
clone.Scheme = "socks5"
|
||||
}
|
||||
clone.User = nil
|
||||
clone.Path = ""
|
||||
clone.RawPath = ""
|
||||
clone.RawQuery = ""
|
||||
clone.Fragment = ""
|
||||
return clone.String()
|
||||
}
|
||||
|
||||
func validateBrowserBinaryPath(path string) error {
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("path points to a directory")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// resolveBrowserBinaryPath prefers an explicit browser path. If no explicit path is provided,
|
||||
// it falls back to launcher autodiscovery and lets Rod handle auto-download when no binary is found.
|
||||
func resolveBrowserBinaryPath(browserPath string, lookPath func() (string, bool)) (string, error) {
|
||||
if browserPath != "" {
|
||||
if err := validateBrowserBinaryPath(browserPath); err != nil {
|
||||
return "", fmt.Errorf("invalid browser_path %q: %w", browserPath, err)
|
||||
}
|
||||
return browserPath, nil
|
||||
}
|
||||
|
||||
path, has := lookPath()
|
||||
if has {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Check whether browser instance is already created
|
||||
func (b *Browser) IsInitialized() bool {
|
||||
if b.browserAddr != "" {
|
||||
@@ -69,31 +161,123 @@ func (b *Browser) IsInitialized() bool {
|
||||
}
|
||||
|
||||
// Open URL
|
||||
func (b *Browser) Navigate(URL string) *rod.Page {
|
||||
func (b *Browser) Navigate(URL string) (*rod.Page, error) {
|
||||
logrus.Debug("Navigate to: ", URL)
|
||||
|
||||
b.browser = rod.New().ControlURL(b.browserAddr)
|
||||
b.browser.MustConnect()
|
||||
b.browser.SetCookies(nil)
|
||||
browser := rod.New().ControlURL(b.browserAddr).Timeout(b.Timeout)
|
||||
if err := browser.Connect(); err != nil {
|
||||
return nil, fmt.Errorf("browser connect failed: %w", err)
|
||||
}
|
||||
b.browser = browser
|
||||
if err := b.browser.SetCookies(nil); err != nil {
|
||||
return nil, fmt.Errorf("browser cookie reset failed: %w", err)
|
||||
}
|
||||
|
||||
//page := b.browser.MustPage(URL)
|
||||
page := stealth.MustPage(b.browser)
|
||||
page.MustEmulate(devices.Device{
|
||||
//UserAgent: uarand.GetRandom(),
|
||||
AcceptLanguage: b.LanguageCode,
|
||||
})
|
||||
page.MustNavigate(URL)
|
||||
// Handle proxy authentication before any navigations
|
||||
if b.ProxyURL != "" {
|
||||
proxyUrl, _ := url.Parse(b.ProxyURL)
|
||||
|
||||
// Always ignore certificate errors when using proxies
|
||||
// This fixes the ERR_CERT_AUTHORITY_INVALID error for SOCKS5 proxies
|
||||
if err := b.browser.IgnoreCertErrors(true); err != nil {
|
||||
return nil, fmt.Errorf("configure proxy cert handling failed: %w", err)
|
||||
}
|
||||
|
||||
if proxyUrl.User != nil && (proxyUrl.Scheme == "http" || proxyUrl.Scheme == "https") {
|
||||
username := proxyUrl.User.Username()
|
||||
password, _ := proxyUrl.User.Password()
|
||||
// Launch auth handler before any navigation occurs
|
||||
go func() {
|
||||
if err := b.browser.HandleAuth(username, password)(); err != nil {
|
||||
logrus.Debugf("Proxy auth handler stopped: %v", err)
|
||||
}
|
||||
}()
|
||||
} else if proxyUrl.User != nil && (proxyUrl.Scheme == "socks5" || proxyUrl.Scheme == "socks5h") {
|
||||
// This callback handles HTTP proxy auth challenges; it doesn't authenticate SOCKS proxies.
|
||||
logrus.Debug("SOCKS proxy credentials are not handled by browser auth callback")
|
||||
}
|
||||
} else if b.Insecure {
|
||||
// Still respect the insecure flag if no proxy is used
|
||||
if err := b.browser.IgnoreCertErrors(true); err != nil {
|
||||
return nil, fmt.Errorf("configure insecure mode failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
version, err := b.browser.Version()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read browser version failed: %w", err)
|
||||
}
|
||||
ua := strings.ReplaceAll(version.UserAgent, "HeadlessChrome/", "Chrome/")
|
||||
|
||||
var page *rod.Page
|
||||
|
||||
if b.UseStealth {
|
||||
page, err = stealth.Page(b.browser)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create stealth page failed: %w", err)
|
||||
}
|
||||
err = page.Emulate(devices.Device{
|
||||
AcceptLanguage: b.LanguageCode,
|
||||
UserAgent: ua,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("emulate stealth page failed: %w", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
page, err = b.browser.Page(proto.TargetCreateTarget{URL: "about:blank"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create page failed: %w", err)
|
||||
}
|
||||
|
||||
err = page.Emulate(devices.Device{
|
||||
AcceptLanguage: b.LanguageCode,
|
||||
UserAgent: ua,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("emulate page failed: %w", err)
|
||||
}
|
||||
|
||||
err = proto.EmulationSetDeviceMetricsOverride{
|
||||
Width: 1920,
|
||||
Height: 1080,
|
||||
DeviceScaleFactor: 1,
|
||||
Mobile: false,
|
||||
ScreenWidth: &[]int{1920}[0],
|
||||
ScreenHeight: &[]int{1080}[0],
|
||||
}.Call(page)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("set device metrics failed: %w", err)
|
||||
}
|
||||
}
|
||||
//EnableCustomStealth(page)
|
||||
|
||||
timedPage := page.Timeout(b.Timeout)
|
||||
|
||||
err = timedPage.Navigate(URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Avoid panics from MustWaitLoad when the target navigates/closes mid-wait
|
||||
if werr := timedPage.WaitLoad(); werr != nil {
|
||||
if errors.Is(werr, context.DeadlineExceeded) {
|
||||
// Some engines keep loading background resources while the DOM is already usable.
|
||||
// Treat load timeout as non-fatal and let engine-specific selector timeouts decide.
|
||||
logrus.Debugf("WaitLoad timed out after %s; continuing with partial page state", b.Timeout)
|
||||
} else {
|
||||
logrus.Debugf("WaitLoad returned early: %v", werr)
|
||||
}
|
||||
}
|
||||
|
||||
wait := page.MustWaitRequestIdle()
|
||||
// may cause bugs with google
|
||||
if b.WaitRequests {
|
||||
wait := timedPage.WaitRequestIdle(300*time.Millisecond, nil, nil, nil)
|
||||
wait()
|
||||
}
|
||||
|
||||
// Wait till page loads
|
||||
//time.Sleep(b.WaitLoadTime)
|
||||
|
||||
return page
|
||||
time.Sleep(b.WaitLoadTime)
|
||||
return page, nil
|
||||
}
|
||||
|
||||
func (b *Browser) Close() error {
|
||||
|
||||
@@ -38,13 +38,12 @@ func TestBot(t *testing.T) {
|
||||
t.Fatalf("Error failed initializing browser: %s", err)
|
||||
}
|
||||
|
||||
page := browser.Navigate("https://bot.sannysoft.com")
|
||||
page, _ := browser.Navigate("https://bot.sannysoft.com")
|
||||
page.MustScreenshotFullPage("./test/screenshot_bot.png")
|
||||
|
||||
page = browser.Navigate("https://www.whatismybrowser.com/")
|
||||
page, _ = browser.Navigate("https://www.whatismybrowser.com/")
|
||||
page.MustScreenshotFullPage("./test/screenshot_browser.png")
|
||||
|
||||
page = browser.Navigate("https://abrahamjuliot.github.io/creepjs/")
|
||||
page, _ = browser.Navigate("https://abrahamjuliot.github.io/creepjs/")
|
||||
page.MustScreenshotFullPage("./test/screenshot_creep.png")
|
||||
|
||||
}
|
||||
|
||||
140
core/cache.go
Normal file
140
core/cache.go
Normal file
@@ -0,0 +1,140 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CacheEntry struct {
|
||||
Data []byte
|
||||
CreatedAt time.Time
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
// ResponseCache is a bounded in-memory TTL cache for dedicated endpoint responses.
|
||||
type ResponseCache struct {
|
||||
mu sync.Mutex
|
||||
entries map[string]CacheEntry
|
||||
ttl time.Duration
|
||||
maxSize int
|
||||
hits int
|
||||
misses int
|
||||
bypasses int
|
||||
evictions int
|
||||
}
|
||||
|
||||
func NewResponseCache(ttl time.Duration, maxSize int) *ResponseCache {
|
||||
return &ResponseCache{
|
||||
entries: make(map[string]CacheEntry),
|
||||
ttl: ttl,
|
||||
maxSize: maxSize,
|
||||
}
|
||||
}
|
||||
|
||||
func BuildCacheKey(engine string, action string, q Query) string {
|
||||
raw := fmt.Sprintf(
|
||||
"%s|%s|%s|%s|%s|%s|%s|%d|%d|%t|%t|%s",
|
||||
engine,
|
||||
action,
|
||||
q.Text,
|
||||
q.LangCode,
|
||||
q.DateInterval,
|
||||
q.Filetype,
|
||||
q.Site,
|
||||
q.Limit,
|
||||
q.Start,
|
||||
q.Filter,
|
||||
q.Answers,
|
||||
q.ProxyOverride,
|
||||
)
|
||||
hash := sha256.Sum256([]byte(raw))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
func (c *ResponseCache) Get(key string) ([]byte, bool) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
c.pruneExpiredLocked(time.Now())
|
||||
|
||||
entry, ok := c.entries[key]
|
||||
if !ok {
|
||||
c.misses++
|
||||
return nil, false
|
||||
}
|
||||
|
||||
c.hits++
|
||||
return entry.Data, true
|
||||
}
|
||||
|
||||
func (c *ResponseCache) Set(key string, data []byte) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
c.pruneExpiredLocked(now)
|
||||
|
||||
if _, exists := c.entries[key]; !exists && len(c.entries) >= c.maxSize {
|
||||
c.evictOldestLocked()
|
||||
}
|
||||
|
||||
c.entries[key] = CacheEntry{
|
||||
Data: data,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(c.ttl),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ResponseCache) RecordBypass() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.bypasses++
|
||||
}
|
||||
|
||||
func (c *ResponseCache) Stats() map[string]interface{} {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
c.pruneExpiredLocked(time.Now())
|
||||
|
||||
return map[string]interface{}{
|
||||
"status": true,
|
||||
"entries": len(c.entries),
|
||||
"hits": c.hits,
|
||||
"misses": c.misses,
|
||||
"bypasses": c.bypasses,
|
||||
"evictions": c.evictions,
|
||||
"ttl_seconds": int(c.ttl / time.Second),
|
||||
"max_size": c.maxSize,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ResponseCache) pruneExpiredLocked(now time.Time) {
|
||||
for key, entry := range c.entries {
|
||||
if !now.Before(entry.ExpiresAt) {
|
||||
delete(c.entries, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ResponseCache) evictOldestLocked() {
|
||||
var (
|
||||
oldestKey string
|
||||
oldestCreated time.Time
|
||||
)
|
||||
|
||||
for key, entry := range c.entries {
|
||||
if oldestKey == "" || entry.CreatedAt.Before(oldestCreated) {
|
||||
oldestKey = key
|
||||
oldestCreated = entry.CreatedAt
|
||||
}
|
||||
}
|
||||
|
||||
if oldestKey != "" {
|
||||
delete(c.entries, oldestKey)
|
||||
c.evictions++
|
||||
}
|
||||
}
|
||||
155
core/cache_test.go
Normal file
155
core/cache_test.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestResponseCacheSetAndGet(t *testing.T) {
|
||||
cache := NewResponseCache(5*time.Second, 10)
|
||||
key := BuildCacheKey("google", "search", Query{Text: "golang", Limit: 10})
|
||||
|
||||
if _, ok := cache.Get(key); ok {
|
||||
t.Fatal("expected initial cache miss")
|
||||
}
|
||||
|
||||
data := []byte(`[{"rank":1}]`)
|
||||
cache.Set(key, data)
|
||||
|
||||
got, ok := cache.Get(key)
|
||||
if !ok {
|
||||
t.Fatal("expected cache hit")
|
||||
}
|
||||
if string(got) != string(data) {
|
||||
t.Fatalf("unexpected cached value: got %s want %s", got, data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseCacheExpiration(t *testing.T) {
|
||||
cache := NewResponseCache(40*time.Millisecond, 10)
|
||||
key := BuildCacheKey("google", "search", Query{Text: "expire"})
|
||||
cache.Set(key, []byte(`[]`))
|
||||
|
||||
if _, ok := cache.Get(key); !ok {
|
||||
t.Fatal("expected cache hit before expiration")
|
||||
}
|
||||
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
|
||||
if _, ok := cache.Get(key); ok {
|
||||
t.Fatal("expected cache miss after expiration")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseCacheEvictsOldestEntry(t *testing.T) {
|
||||
cache := NewResponseCache(time.Minute, 2)
|
||||
|
||||
firstKey := BuildCacheKey("google", "search", Query{Text: "first"})
|
||||
secondKey := BuildCacheKey("google", "search", Query{Text: "second"})
|
||||
thirdKey := BuildCacheKey("google", "search", Query{Text: "third"})
|
||||
|
||||
cache.Set(firstKey, []byte(`["first"]`))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
cache.Set(secondKey, []byte(`["second"]`))
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
cache.Set(thirdKey, []byte(`["third"]`))
|
||||
|
||||
if _, ok := cache.Get(firstKey); ok {
|
||||
t.Fatal("expected oldest entry to be evicted")
|
||||
}
|
||||
if _, ok := cache.Get(secondKey); !ok {
|
||||
t.Fatal("expected newer entry to remain cached")
|
||||
}
|
||||
if _, ok := cache.Get(thirdKey); !ok {
|
||||
t.Fatal("expected newest entry to remain cached")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseCacheStats(t *testing.T) {
|
||||
cache := NewResponseCache(time.Minute, 2)
|
||||
key := BuildCacheKey("google", "search", Query{Text: "stats"})
|
||||
|
||||
if _, ok := cache.Get(key); ok {
|
||||
t.Fatal("expected miss for empty cache")
|
||||
}
|
||||
|
||||
cache.Set(key, []byte(`[]`))
|
||||
if _, ok := cache.Get(key); !ok {
|
||||
t.Fatal("expected cache hit")
|
||||
}
|
||||
cache.RecordBypass()
|
||||
|
||||
stats := cache.Stats()
|
||||
if got := stats["status"]; got != true {
|
||||
t.Fatalf("expected enabled status, got %v", got)
|
||||
}
|
||||
if got := stats["entries"].(int); got != 1 {
|
||||
t.Fatalf("expected 1 entry, got %d", got)
|
||||
}
|
||||
if got := stats["hits"].(int); got != 1 {
|
||||
t.Fatalf("expected 1 hit, got %d", got)
|
||||
}
|
||||
if got := stats["misses"].(int); got != 1 {
|
||||
t.Fatalf("expected 1 miss, got %d", got)
|
||||
}
|
||||
if got := stats["bypasses"].(int); got != 1 {
|
||||
t.Fatalf("expected 1 bypass, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildCacheKeyChangesWithPaginationAndFlags(t *testing.T) {
|
||||
base := Query{
|
||||
Text: "golang",
|
||||
LangCode: "EN",
|
||||
Limit: 10,
|
||||
Start: 0,
|
||||
Filter: true,
|
||||
Answers: false,
|
||||
}
|
||||
|
||||
baseKey := BuildCacheKey("google", "search", base)
|
||||
|
||||
if same := BuildCacheKey("google", "search", base); same != baseKey {
|
||||
t.Fatal("expected deterministic key for same query")
|
||||
}
|
||||
if changed := BuildCacheKey("google", "search", Query{
|
||||
Text: "golang",
|
||||
LangCode: "EN",
|
||||
Limit: 20,
|
||||
Start: 0,
|
||||
Filter: true,
|
||||
Answers: false,
|
||||
}); changed == baseKey {
|
||||
t.Fatal("expected limit to affect cache key")
|
||||
}
|
||||
if changed := BuildCacheKey("google", "search", Query{
|
||||
Text: "golang",
|
||||
LangCode: "EN",
|
||||
Limit: 10,
|
||||
Start: 10,
|
||||
Filter: true,
|
||||
Answers: false,
|
||||
}); changed == baseKey {
|
||||
t.Fatal("expected start to affect cache key")
|
||||
}
|
||||
if changed := BuildCacheKey("google", "search", Query{
|
||||
Text: "golang",
|
||||
LangCode: "EN",
|
||||
Limit: 10,
|
||||
Start: 0,
|
||||
Filter: false,
|
||||
Answers: false,
|
||||
}); changed == baseKey {
|
||||
t.Fatal("expected filter to affect cache key")
|
||||
}
|
||||
if changed := BuildCacheKey("google", "search", Query{
|
||||
Text: "golang",
|
||||
LangCode: "EN",
|
||||
Limit: 10,
|
||||
Start: 0,
|
||||
Filter: true,
|
||||
Answers: true,
|
||||
}); changed == baseKey {
|
||||
t.Fatal("expected answers to affect cache key")
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ func NewSolver(apikey string) *CaptchaSolver {
|
||||
return &cs
|
||||
}
|
||||
|
||||
func (cs *CaptchaSolver) SolveReCaptcha2(sitekey, pageUrl, dataS string) (string, error) {
|
||||
func (cs *CaptchaSolver) SolveReCaptcha2(sitekey, pageUrl, dataS string) (string, string, error) {
|
||||
cap := api2captcha.ReCaptcha{
|
||||
SiteKey: sitekey,
|
||||
Url: pageUrl,
|
||||
|
||||
@@ -13,7 +13,7 @@ func Test2Captcha(t *testing.T) {
|
||||
sitekey := "6LfwuyUTAAAAAOAmoS0fdqijC2PbbdH4kjq62Y1b"
|
||||
url := "https://www.google.com/sorry/index?continue=https://www.google.de/search%3Fhl%3DDE%26lr%3Dlang_de%26nfpr%3D1%26num%3D500%26pws%3D0%26q%3Dwhere%2Bwhy%2Beach&hl=DE&q=EgRegw55GObHiq4GIjDqmzFKayGXrS2-s9ooWfcskhpK8-6tIjWSaSvhxd3f5eAyUXj7lYq2DYLDXB8ASz0yAXJaAUM"
|
||||
datas := "Ghk0n7ZQNDS0c7ES53eef_YBfSdfeXnyRD0p2OR0R4Dg91CUXKS_hio5Do6TpJ8sHhhOat_NymTASZGe1gqAjP7w9dSvhvRT7QXsrdziO3JPngLDSRzDdjT42GDcSbO0kzInlDPxe1yy2t4yifo9xHpMnlZU7pTVNTQUIXqOMLHAR-iERi6aoSQDQ4d-88-jW3LEinquxEut0OhHG2l2stwG9AnCmNvCsUNJda-H24saFlOh5csK9KNXeeQmpr6at52_skMIMiLXSlY56vYFVCRMkXLQdAM"
|
||||
resp, err := solver.SolveReCaptcha2(sitekey, url, datas)
|
||||
resp, _, err := solver.SolveReCaptcha2(sitekey, url, datas)
|
||||
if err != nil || resp == "" {
|
||||
t.Fatalf("Failed to solve recaptchaV2: %s", err)
|
||||
}
|
||||
|
||||
210
core/circuit_breaker.go
Normal file
210
core/circuit_breaker.go
Normal file
@@ -0,0 +1,210 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type CircuitState int
|
||||
|
||||
const (
|
||||
CircuitClosed CircuitState = iota
|
||||
CircuitOpen
|
||||
CircuitHalfOpen
|
||||
)
|
||||
|
||||
func (s CircuitState) String() string {
|
||||
switch s {
|
||||
case CircuitClosed:
|
||||
return "closed"
|
||||
case CircuitOpen:
|
||||
return "open"
|
||||
case CircuitHalfOpen:
|
||||
return "half-open"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
type CircuitBreakerConfig struct {
|
||||
FailureThreshold int
|
||||
RecoveryTimeout time.Duration
|
||||
SuccessThreshold int
|
||||
}
|
||||
|
||||
func DefaultCircuitBreakerConfig() CircuitBreakerConfig {
|
||||
return CircuitBreakerConfig{
|
||||
FailureThreshold: 5,
|
||||
RecoveryTimeout: 60 * time.Second,
|
||||
SuccessThreshold: 2,
|
||||
}
|
||||
}
|
||||
|
||||
// CircuitBreaker tracks failure state for one engine.
|
||||
type CircuitBreaker struct {
|
||||
mu sync.RWMutex
|
||||
name string
|
||||
state CircuitState
|
||||
config CircuitBreakerConfig
|
||||
failureCount int
|
||||
successCount int
|
||||
lastFailureTime time.Time
|
||||
lastStateChange time.Time
|
||||
}
|
||||
|
||||
func NewCircuitBreaker(name string, cfg CircuitBreakerConfig) *CircuitBreaker {
|
||||
return &CircuitBreaker{
|
||||
name: name,
|
||||
state: CircuitClosed,
|
||||
config: cfg,
|
||||
lastStateChange: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) AllowRequest() bool {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
switch cb.state {
|
||||
case CircuitClosed:
|
||||
return true
|
||||
case CircuitOpen:
|
||||
if time.Since(cb.lastFailureTime) >= cb.config.RecoveryTimeout {
|
||||
cb.setState(CircuitHalfOpen)
|
||||
logrus.Infof("[CircuitBreaker][%s] Recovery timeout elapsed, moving to half-open", cb.name)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
case CircuitHalfOpen:
|
||||
return true
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) RecordSuccess() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
switch cb.state {
|
||||
case CircuitHalfOpen:
|
||||
cb.successCount++
|
||||
if cb.successCount >= cb.config.SuccessThreshold {
|
||||
cb.setState(CircuitClosed)
|
||||
cb.failureCount = 0
|
||||
cb.successCount = 0
|
||||
logrus.Infof("[CircuitBreaker][%s] Recovered, circuit closed", cb.name)
|
||||
}
|
||||
case CircuitClosed:
|
||||
cb.failureCount = 0
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) RecordFailure() {
|
||||
cb.mu.Lock()
|
||||
defer cb.mu.Unlock()
|
||||
|
||||
cb.lastFailureTime = time.Now()
|
||||
|
||||
switch cb.state {
|
||||
case CircuitClosed:
|
||||
cb.failureCount++
|
||||
if cb.failureCount >= cb.config.FailureThreshold {
|
||||
cb.setState(CircuitOpen)
|
||||
logrus.Warnf("[CircuitBreaker][%s] Circuit OPENED after %d consecutive failures (will retry in %s)",
|
||||
cb.name, cb.failureCount, cb.config.RecoveryTimeout)
|
||||
}
|
||||
case CircuitHalfOpen:
|
||||
cb.setState(CircuitOpen)
|
||||
cb.successCount = 0
|
||||
logrus.Warnf("[CircuitBreaker][%s] Failed during half-open, circuit re-opened", cb.name)
|
||||
}
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) State() CircuitState {
|
||||
cb.mu.RLock()
|
||||
defer cb.mu.RUnlock()
|
||||
return cb.state
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) Stats() map[string]interface{} {
|
||||
cb.mu.RLock()
|
||||
defer cb.mu.RUnlock()
|
||||
|
||||
stats := map[string]interface{}{
|
||||
"engine": cb.name,
|
||||
"state": cb.state.String(),
|
||||
"failure_count": cb.failureCount,
|
||||
"last_changed": cb.lastStateChange.Format(time.RFC3339),
|
||||
}
|
||||
|
||||
if cb.state == CircuitOpen {
|
||||
remaining := cb.config.RecoveryTimeout - time.Since(cb.lastFailureTime)
|
||||
if remaining < 0 {
|
||||
remaining = 0
|
||||
}
|
||||
|
||||
// Expose retry_in as integer seconds for easier client-side processing.
|
||||
retryInSeconds := int64(0)
|
||||
if remaining > 0 {
|
||||
retryInSeconds = int64((remaining + time.Second - time.Nanosecond) / time.Second)
|
||||
}
|
||||
stats["retry_in"] = retryInSeconds
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
func (cb *CircuitBreaker) setState(state CircuitState) {
|
||||
cb.state = state
|
||||
cb.lastStateChange = time.Now()
|
||||
}
|
||||
|
||||
type CircuitBreakerManager struct {
|
||||
mu sync.RWMutex
|
||||
breakers map[string]*CircuitBreaker
|
||||
config CircuitBreakerConfig
|
||||
}
|
||||
|
||||
func NewCircuitBreakerManager(cfg CircuitBreakerConfig) *CircuitBreakerManager {
|
||||
return &CircuitBreakerManager{
|
||||
breakers: make(map[string]*CircuitBreaker),
|
||||
config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CircuitBreakerManager) Get(engineName string) *CircuitBreaker {
|
||||
m.mu.RLock()
|
||||
if cb, ok := m.breakers[engineName]; ok {
|
||||
m.mu.RUnlock()
|
||||
return cb
|
||||
}
|
||||
m.mu.RUnlock()
|
||||
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
if cb, ok := m.breakers[engineName]; ok {
|
||||
return cb
|
||||
}
|
||||
|
||||
cb := NewCircuitBreaker(engineName, m.config)
|
||||
m.breakers[engineName] = cb
|
||||
return cb
|
||||
}
|
||||
|
||||
func (m *CircuitBreakerManager) AllStats() []map[string]interface{} {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
stats := make([]map[string]interface{}, 0, len(m.breakers))
|
||||
for _, cb := range m.breakers {
|
||||
stats = append(stats, cb.Stats())
|
||||
}
|
||||
return stats
|
||||
}
|
||||
|
||||
var ErrCircuitOpen = fmt.Errorf("circuit breaker is open - engine temporarily disabled")
|
||||
165
core/circuit_breaker_test.go
Normal file
165
core/circuit_breaker_test.go
Normal file
@@ -0,0 +1,165 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func newTestCircuitBreaker(t *testing.T, cfg CircuitBreakerConfig) *CircuitBreaker {
|
||||
t.Helper()
|
||||
return NewCircuitBreaker("test-engine", cfg)
|
||||
}
|
||||
|
||||
// TestCircuitBreaker_OpensAfterThreshold verifies that consecutive failures in closed state
|
||||
// move the breaker to open exactly on configured threshold and block new requests.
|
||||
func TestCircuitBreaker_OpensAfterThreshold(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
FailureThreshold: 3,
|
||||
RecoveryTimeout: time.Second,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := newTestCircuitBreaker(t, cfg)
|
||||
|
||||
cb.RecordFailure()
|
||||
cb.RecordFailure()
|
||||
if cb.State() != CircuitClosed {
|
||||
t.Fatalf("expected closed after 2 failures, got: %s", cb.State())
|
||||
}
|
||||
|
||||
cb.RecordFailure()
|
||||
if cb.State() != CircuitOpen {
|
||||
t.Fatalf("expected open after %d failures, got: %s", cfg.FailureThreshold, cb.State())
|
||||
}
|
||||
if cb.AllowRequest() {
|
||||
t.Error("expected request blocked in open state")
|
||||
}
|
||||
}
|
||||
|
||||
// TestCircuitBreaker_RecoveryToHalfOpen verifies timed recovery from open to half-open
|
||||
// when recovery timeout elapses and a new request is attempted.
|
||||
func TestCircuitBreaker_RecoveryToHalfOpen(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
FailureThreshold: 2,
|
||||
RecoveryTimeout: 50 * time.Millisecond,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := newTestCircuitBreaker(t, cfg)
|
||||
|
||||
cb.RecordFailure()
|
||||
cb.RecordFailure()
|
||||
if cb.State() != CircuitOpen {
|
||||
t.Fatal("expected open")
|
||||
}
|
||||
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
if !cb.AllowRequest() {
|
||||
t.Error("should allow request after recovery timeout")
|
||||
}
|
||||
if cb.State() != CircuitHalfOpen {
|
||||
t.Errorf("expected half-open, got: %s", cb.State())
|
||||
}
|
||||
}
|
||||
|
||||
// TestCircuitBreaker_HalfOpenSuccessClosesCircuit verifies that half-open state closes
|
||||
// only after configured number of successful probes.
|
||||
func TestCircuitBreaker_HalfOpenSuccessClosesCircuit(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
RecoveryTimeout: 20 * time.Millisecond,
|
||||
SuccessThreshold: 2,
|
||||
}
|
||||
cb := newTestCircuitBreaker(t, cfg)
|
||||
|
||||
cb.RecordFailure()
|
||||
if cb.State() != CircuitOpen {
|
||||
t.Fatalf("expected open, got: %s", cb.State())
|
||||
}
|
||||
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
if !cb.AllowRequest() {
|
||||
t.Fatal("expected request to pass in recovery window")
|
||||
}
|
||||
if cb.State() != CircuitHalfOpen {
|
||||
t.Fatalf("expected half-open after recovery timeout, got: %s", cb.State())
|
||||
}
|
||||
|
||||
cb.RecordSuccess()
|
||||
if cb.State() != CircuitHalfOpen {
|
||||
t.Fatalf("expected to stay half-open until success threshold reached, got: %s", cb.State())
|
||||
}
|
||||
|
||||
cb.RecordSuccess()
|
||||
if cb.State() != CircuitClosed {
|
||||
t.Fatalf("expected closed after success threshold reached, got: %s", cb.State())
|
||||
}
|
||||
}
|
||||
|
||||
// TestCircuitBreaker_HalfOpenFailureReopens verifies that a failed probe in half-open
|
||||
// immediately re-opens the circuit.
|
||||
func TestCircuitBreaker_HalfOpenFailureReopens(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
RecoveryTimeout: 20 * time.Millisecond,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := newTestCircuitBreaker(t, cfg)
|
||||
|
||||
cb.RecordFailure()
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
if !cb.AllowRequest() {
|
||||
t.Fatal("expected probe request in half-open")
|
||||
}
|
||||
if cb.State() != CircuitHalfOpen {
|
||||
t.Fatalf("expected half-open, got: %s", cb.State())
|
||||
}
|
||||
|
||||
cb.RecordFailure()
|
||||
if cb.State() != CircuitOpen {
|
||||
t.Fatalf("expected open after failed half-open probe, got: %s", cb.State())
|
||||
}
|
||||
}
|
||||
|
||||
// TestCircuitBreaker_Stats verifies stats payload fields and that retry_in is exposed
|
||||
// only when breaker is open.
|
||||
func TestCircuitBreaker_Stats(t *testing.T) {
|
||||
cb := NewCircuitBreaker("test-engine", DefaultCircuitBreakerConfig())
|
||||
cb.RecordFailure()
|
||||
|
||||
stats := cb.Stats()
|
||||
if stats["engine"] != "test-engine" {
|
||||
t.Fatalf("expected engine=test-engine, got: %v", stats["engine"])
|
||||
}
|
||||
if stats["state"] != "closed" {
|
||||
t.Fatalf("expected state=closed, got: %v", stats["state"])
|
||||
}
|
||||
if stats["failure_count"].(int) != 1 {
|
||||
t.Fatalf("expected failure_count=1, got: %v", stats["failure_count"])
|
||||
}
|
||||
if _, ok := stats["retry_in"]; ok {
|
||||
t.Fatalf("did not expect retry_in in closed state, got: %v", stats["retry_in"])
|
||||
}
|
||||
|
||||
openCfg := CircuitBreakerConfig{FailureThreshold: 1, RecoveryTimeout: time.Second, SuccessThreshold: 1}
|
||||
openCB := NewCircuitBreaker("open-engine", openCfg)
|
||||
openCB.RecordFailure()
|
||||
openStats := openCB.Stats()
|
||||
retryIn, ok := openStats["retry_in"].(int64)
|
||||
if !ok {
|
||||
t.Fatalf("expected retry_in int64 in open state, got: %T", openStats["retry_in"])
|
||||
}
|
||||
if retryIn <= 0 {
|
||||
t.Fatalf("expected retry_in > 0 in open state, got: %d", retryIn)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCircuitBreakerManager_AllStats verifies manager creates and reports per-engine breakers.
|
||||
func TestCircuitBreakerManager_AllStats(t *testing.T) {
|
||||
mgr := NewCircuitBreakerManager(DefaultCircuitBreakerConfig())
|
||||
mgr.Get("google")
|
||||
mgr.Get("yandex")
|
||||
|
||||
stats := mgr.AllStats()
|
||||
if len(stats) != 2 {
|
||||
t.Errorf("expected 2 entries, got: %d", len(stats))
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,26 @@ type SearchResult struct {
|
||||
Ad bool `json:"ad"`
|
||||
}
|
||||
|
||||
func DeduplicateResults(results []SearchResult) []SearchResult {
|
||||
unique := make(map[string]bool)
|
||||
var deduped []SearchResult
|
||||
|
||||
for _, result := range results {
|
||||
if result.URL == "" {
|
||||
continue
|
||||
}
|
||||
if !unique[result.URL] {
|
||||
unique[result.URL] = true
|
||||
deduped = append(deduped, result)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(deduped, func(i, j int) bool {
|
||||
return deduped[i].Rank < deduped[j].Rank
|
||||
})
|
||||
return deduped
|
||||
}
|
||||
|
||||
func ConvertSearchResultsMap(searchResultsMap map[string]SearchResult) *[]SearchResult {
|
||||
searchResults := []SearchResult{}
|
||||
|
||||
@@ -34,13 +54,28 @@ func ConvertSearchResultsMap(searchResultsMap map[string]SearchResult) *[]Search
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Text string
|
||||
LangCode string // eg. EN, ES, RU...
|
||||
DateInterval string // format: YYYYMMDD..YYYMMDD - 20181010..20231010
|
||||
Filetype string // File extension to search.
|
||||
Site string // Search site
|
||||
Limit int // Limit the number of results
|
||||
Answers bool // Include question and answers from SERP page to results with negative indexes
|
||||
Text string
|
||||
LangCode string // eg. EN, ES, RU...
|
||||
DateInterval string // format: YYYYMMDD..YYYMMDD - 20181010..20231010
|
||||
Filetype string // File extension to search.
|
||||
Site string // Search site
|
||||
Limit int // Limit the number of results
|
||||
Start int // Search offset for pagination (Google uses 0, 10, 20...)
|
||||
Filter bool // Filter duplicates (google) (false: include similar, true: hide similar)
|
||||
Answers bool // Include question and answers from SERP page to results with negative indexes
|
||||
ProxyURL string // Proxy URL for raw requests
|
||||
ProxyOverride string // Request-scoped proxy override: tag or direct
|
||||
Insecure bool // Allow insecure TLS connections
|
||||
}
|
||||
|
||||
func ComputePagination(start int, pageSize int) (int, int, error) {
|
||||
if pageSize <= 0 {
|
||||
return 0, 0, errors.New("pageSize must be > 0")
|
||||
}
|
||||
if start < 0 {
|
||||
return 0, 0, errors.New("start must be >= 0")
|
||||
}
|
||||
return start / pageSize, start % pageSize, nil
|
||||
}
|
||||
|
||||
func (q Query) IsEmpty() bool {
|
||||
@@ -63,11 +98,30 @@ func (searchQuery *Query) InitFromContext(reqCtx *fiber.Ctx) error {
|
||||
}
|
||||
searchQuery.Limit = limit
|
||||
|
||||
start, err := strconv.Atoi(reqCtx.Query("start", "0"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if start < 0 {
|
||||
return errors.New("start must be >= 0")
|
||||
}
|
||||
searchQuery.Start = start
|
||||
|
||||
searchQuery.Filter, err = strconv.ParseBool(reqCtx.Query("filter", "1"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
searchQuery.Answers, err = strconv.ParseBool(reqCtx.Query("answers", "0"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
searchQuery.ProxyOverride, err = NormalizeProxyRequestOverride(reqCtx.Get("X-Use-Proxy"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if searchQuery.IsEmpty() {
|
||||
return errors.New("Query cannot be empty")
|
||||
}
|
||||
|
||||
74
core/http_client.go
Normal file
74
core/http_client.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
utls "github.com/refraction-networking/utls"
|
||||
)
|
||||
|
||||
const rawHTTPTimeout = 10 * time.Second
|
||||
|
||||
func NewRawHTTPClient(query Query) (*http.Client, error) {
|
||||
transport, err := newRawTransport(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: transport,
|
||||
Timeout: rawHTTPTimeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newRawTransport(query Query) (*http.Transport, error) {
|
||||
transport := &http.Transport{}
|
||||
if query.Insecure {
|
||||
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
proxyURL, err := NormalizeProxyURL(query.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if proxyURL != "" {
|
||||
parsed, err := url.Parse(proxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Keep proxied requests on the standard transport path so SOCKS5/SOCKS5H
|
||||
// resolution and routing are handled by the configured proxy correctly.
|
||||
transport.Proxy = http.ProxyURL(parsed)
|
||||
return transport, nil
|
||||
}
|
||||
|
||||
transport.DialTLSContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
dialer := &net.Dialer{}
|
||||
rawConn, err := dialer.DialContext(ctx, network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hostname := strings.Split(addr, ":")[0]
|
||||
config := &utls.Config{
|
||||
ServerName: hostname,
|
||||
InsecureSkipVerify: query.Insecure,
|
||||
}
|
||||
|
||||
uconn := utls.UClient(rawConn, config, utls.HelloChrome_Auto)
|
||||
if err := uconn.Handshake(); err != nil {
|
||||
rawConn.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return uconn, nil
|
||||
}
|
||||
|
||||
return transport, nil
|
||||
}
|
||||
@@ -14,20 +14,93 @@ type customFormatter struct {
|
||||
}
|
||||
|
||||
func (f *customFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
// var levelColor int
|
||||
// switch entry.Level {
|
||||
// case logrus.DebugLevel, logrus.TraceLevel:
|
||||
// levelColor = 42 // green highlight
|
||||
// case logrus.WarnLevel:
|
||||
// levelColor = 33 // yellow
|
||||
// case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
|
||||
// levelColor = 41 // red highlight
|
||||
// default:
|
||||
// levelColor = 36 // blue
|
||||
// }
|
||||
//[]byte(fmt.Sprintf("[%s] - \x1b[%dm%s\x1b[0m - %s\n", entry.Time.Format(f.TimestampFormat), levelColor, strings.ToUpper(entry.Level.String()), entry.Message))
|
||||
message := entry.Message
|
||||
|
||||
return []byte(fmt.Sprintf("[%s][%s] \t%s\n", entry.Time.Format(f.TimestampFormat), strings.ToUpper(entry.Level.String()), entry.Message)), nil
|
||||
// Check if engine name is provided as a field
|
||||
engineName := ""
|
||||
if engine, exists := entry.Data["engine"]; exists {
|
||||
if engineStr, ok := engine.(string); ok {
|
||||
engineName = engineStr
|
||||
}
|
||||
}
|
||||
|
||||
// Format: [timestamp][level][engine] message
|
||||
if engineName != "" {
|
||||
return []byte(fmt.Sprintf("[%s][%s][%s] %s\n",
|
||||
entry.Time.Format(f.TimestampFormat),
|
||||
strings.ToUpper(entry.Level.String()),
|
||||
engineName,
|
||||
message)), nil
|
||||
}
|
||||
|
||||
// Format: [timestamp][level] message (no engine)
|
||||
return []byte(fmt.Sprintf("[%s][%s] %s\n",
|
||||
entry.Time.Format(f.TimestampFormat),
|
||||
strings.ToUpper(entry.Level.String()),
|
||||
message)), nil
|
||||
}
|
||||
|
||||
// EngineLogger provides simplified logging for search engines
|
||||
type EngineLogger struct {
|
||||
engine string
|
||||
logger *logrus.Entry
|
||||
}
|
||||
|
||||
// NewEngineLogger creates a new logger for a specific search engine
|
||||
func NewEngineLogger(engine string) *EngineLogger {
|
||||
return &EngineLogger{
|
||||
engine: engine,
|
||||
logger: logrus.WithField("engine", engine),
|
||||
}
|
||||
}
|
||||
|
||||
// Debug logs a debug message
|
||||
func (el *EngineLogger) Debug(message string, args ...interface{}) {
|
||||
el.logger.Debugf(message, args...)
|
||||
}
|
||||
|
||||
// Info logs an info message
|
||||
func (el *EngineLogger) Info(message string, args ...interface{}) {
|
||||
el.logger.Infof(message, args...)
|
||||
}
|
||||
|
||||
// Warn logs a warning message
|
||||
func (el *EngineLogger) Warn(message string, args ...interface{}) {
|
||||
el.logger.Warnf(message, args...)
|
||||
}
|
||||
|
||||
// Error logs an error message
|
||||
func (el *EngineLogger) Error(message string, args ...interface{}) {
|
||||
el.logger.Errorf(message, args...)
|
||||
}
|
||||
|
||||
// Fatal logs a fatal message
|
||||
func (el *EngineLogger) Fatal(message string, args ...interface{}) {
|
||||
el.logger.Fatalf(message, args...)
|
||||
}
|
||||
|
||||
// Panic logs a panic message
|
||||
func (el *EngineLogger) Panic(message string, args ...interface{}) {
|
||||
el.logger.Panicf(message, args...)
|
||||
}
|
||||
|
||||
// LogWithEngine logs a message with engine information (deprecated - use EngineLogger instead)
|
||||
func LogWithEngine(level logrus.Level, engine, message string, args ...interface{}) {
|
||||
entry := logrus.WithField("engine", engine)
|
||||
switch level {
|
||||
case logrus.DebugLevel:
|
||||
entry.Debugf(message, args...)
|
||||
case logrus.InfoLevel:
|
||||
entry.Infof(message, args...)
|
||||
case logrus.WarnLevel:
|
||||
entry.Warnf(message, args...)
|
||||
case logrus.ErrorLevel:
|
||||
entry.Errorf(message, args...)
|
||||
case logrus.FatalLevel:
|
||||
entry.Fatalf(message, args...)
|
||||
case logrus.PanicLevel:
|
||||
entry.Panicf(message, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func InitLogger(isVerbose, isDebug bool) {
|
||||
|
||||
144
core/middleware.go
Normal file
144
core/middleware.go
Normal file
@@ -0,0 +1,144 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type JSONErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type CORSConfig struct {
|
||||
AllowOrigins string
|
||||
AllowMethods string
|
||||
AllowHeaders string
|
||||
MaxAge int
|
||||
}
|
||||
|
||||
func DefaultCORSConfig() CORSConfig {
|
||||
return CORSConfig{
|
||||
AllowOrigins: "*",
|
||||
AllowMethods: "GET, POST, OPTIONS",
|
||||
AllowHeaders: "Origin, Content-Type, Accept, Authorization, X-Use-Proxy",
|
||||
MaxAge: 86400,
|
||||
}
|
||||
}
|
||||
|
||||
func CORSMiddleware(cfg CORSConfig) fiber.Handler {
|
||||
cfg = normalizeCORSConfig(cfg)
|
||||
|
||||
return func(c *fiber.Ctx) error {
|
||||
c.Set("Access-Control-Allow-Origin", cfg.AllowOrigins)
|
||||
c.Set("Access-Control-Allow-Methods", cfg.AllowMethods)
|
||||
c.Set("Access-Control-Allow-Headers", cfg.AllowHeaders)
|
||||
c.Set("Access-Control-Max-Age", fmt.Sprintf("%d", cfg.MaxAge))
|
||||
|
||||
if c.Method() == "OPTIONS" {
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeCORSConfig keeps CORS behavior predictable when config provides partial values.
|
||||
func normalizeCORSConfig(cfg CORSConfig) CORSConfig {
|
||||
defaults := DefaultCORSConfig()
|
||||
|
||||
if strings.TrimSpace(cfg.AllowOrigins) == "" {
|
||||
cfg.AllowOrigins = defaults.AllowOrigins
|
||||
}
|
||||
if strings.TrimSpace(cfg.AllowMethods) == "" {
|
||||
cfg.AllowMethods = defaults.AllowMethods
|
||||
}
|
||||
if strings.TrimSpace(cfg.AllowHeaders) == "" {
|
||||
cfg.AllowHeaders = defaults.AllowHeaders
|
||||
}
|
||||
if cfg.MaxAge <= 0 {
|
||||
cfg.MaxAge = defaults.MaxAge
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func RequestLoggerMiddleware() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
start := time.Now()
|
||||
err := c.Next()
|
||||
|
||||
latency := time.Since(start)
|
||||
status := c.Response().StatusCode()
|
||||
if err != nil {
|
||||
if e, ok := err.(*fiber.Error); ok {
|
||||
status = e.Code
|
||||
} else {
|
||||
status = fiber.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
logFields := logrus.Fields{
|
||||
"method": c.Method(),
|
||||
"path": c.Path(),
|
||||
"status": status,
|
||||
"latency": latency.String(),
|
||||
"ip": c.IP(),
|
||||
}
|
||||
if query := c.Query("text"); query != "" {
|
||||
logFields["query"] = query
|
||||
}
|
||||
|
||||
entry := logrus.WithFields(logFields)
|
||||
if status >= 500 {
|
||||
entry.Errorf("%s - request failed", c.Path())
|
||||
} else if status >= 400 {
|
||||
entry.Warnf("%s - request error", c.Path())
|
||||
} else {
|
||||
entry.Infof("%s - request completed", c.Path())
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func JSONErrorMiddleware() fiber.ErrorHandler {
|
||||
return func(c *fiber.Ctx, err error) error {
|
||||
code := fiber.StatusInternalServerError
|
||||
if e, ok := err.(*fiber.Error); ok {
|
||||
code = e.Code
|
||||
}
|
||||
|
||||
resp := JSONErrorResponse{
|
||||
Error: statusText(code),
|
||||
Code: code,
|
||||
Message: err.Error(),
|
||||
}
|
||||
|
||||
c.Set("Content-Type", "application/json")
|
||||
return c.Status(code).JSON(resp)
|
||||
}
|
||||
}
|
||||
|
||||
func statusText(code int) string {
|
||||
switch {
|
||||
case code == 400:
|
||||
return "bad_request"
|
||||
case code == 404:
|
||||
return "not_found"
|
||||
case code == 429:
|
||||
return "rate_limited"
|
||||
case code == 503:
|
||||
return "service_unavailable"
|
||||
case code >= 400 && code < 500:
|
||||
return "client_error"
|
||||
case code >= 500:
|
||||
return "server_error"
|
||||
default:
|
||||
return "error"
|
||||
}
|
||||
}
|
||||
109
core/middleware_test.go
Normal file
109
core/middleware_test.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func TestStatusText(t *testing.T) {
|
||||
tests := []struct {
|
||||
code int
|
||||
expected string
|
||||
}{
|
||||
{400, "bad_request"},
|
||||
{404, "not_found"},
|
||||
{429, "rate_limited"},
|
||||
{503, "service_unavailable"},
|
||||
{401, "client_error"},
|
||||
{500, "server_error"},
|
||||
{200, "error"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
result := statusText(tt.code)
|
||||
if result != tt.expected {
|
||||
t.Errorf("statusText(%d) = %s, want %s", tt.code, result, tt.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Middleware unit tests validate CORS behavior itself (header composition and preflight semantics).
|
||||
func TestCORSMiddleware_UsesConfiguredHeaders(t *testing.T) {
|
||||
app := fiber.New()
|
||||
app.Use(CORSMiddleware(CORSConfig{
|
||||
AllowOrigins: "https://example.com",
|
||||
AllowMethods: "GET,OPTIONS",
|
||||
AllowHeaders: "Authorization,Content-Type",
|
||||
MaxAge: 1200,
|
||||
}))
|
||||
app.Get("/ping", func(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/ping", nil)
|
||||
resp, err := app.Test(req, -1)
|
||||
if err != nil {
|
||||
t.Fatalf("request failed: %v", err)
|
||||
}
|
||||
|
||||
if got := resp.Header.Get("Access-Control-Allow-Origin"); got != "https://example.com" {
|
||||
t.Fatalf("unexpected allow-origin: %q", got)
|
||||
}
|
||||
if got := resp.Header.Get("Access-Control-Allow-Methods"); got != "GET,OPTIONS" {
|
||||
t.Fatalf("unexpected allow-methods: %q", got)
|
||||
}
|
||||
if got := resp.Header.Get("Access-Control-Allow-Headers"); got != "Authorization,Content-Type" {
|
||||
t.Fatalf("unexpected allow-headers: %q", got)
|
||||
}
|
||||
if got := resp.Header.Get("Access-Control-Max-Age"); got != "1200" {
|
||||
t.Fatalf("unexpected max-age: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCORSMiddleware_OPTIONSReturnsNoContent(t *testing.T) {
|
||||
app := fiber.New()
|
||||
app.Use(CORSMiddleware(DefaultCORSConfig()))
|
||||
app.Get("/ping", func(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(http.MethodOptions, "/ping", nil)
|
||||
resp, err := app.Test(req, -1)
|
||||
if err != nil {
|
||||
t.Fatalf("request failed: %v", err)
|
||||
}
|
||||
if resp.StatusCode != fiber.StatusNoContent {
|
||||
t.Fatalf("expected 204 for OPTIONS, got %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeCORSConfig_FillsMissingValues(t *testing.T) {
|
||||
cfg := normalizeCORSConfig(CORSConfig{
|
||||
AllowOrigins: "https://example.com",
|
||||
})
|
||||
def := DefaultCORSConfig()
|
||||
|
||||
if cfg.AllowOrigins != "https://example.com" {
|
||||
t.Fatalf("expected custom allow_origins preserved, got %q", cfg.AllowOrigins)
|
||||
}
|
||||
if cfg.AllowMethods != def.AllowMethods {
|
||||
t.Fatalf("expected default allow_methods, got %q", cfg.AllowMethods)
|
||||
}
|
||||
if cfg.AllowHeaders != def.AllowHeaders {
|
||||
t.Fatalf("expected default allow_headers, got %q", cfg.AllowHeaders)
|
||||
}
|
||||
if cfg.MaxAge != def.MaxAge {
|
||||
t.Fatalf("expected default max_age, got %d", cfg.MaxAge)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultCORSConfig_IncludesProxyOverrideHeader(t *testing.T) {
|
||||
cfg := DefaultCORSConfig()
|
||||
if got := cfg.AllowHeaders; !strings.Contains(got, "X-Use-Proxy") {
|
||||
t.Fatalf("expected allow_headers to include X-Use-Proxy, got %q", got)
|
||||
}
|
||||
}
|
||||
561
core/proxy.go
Normal file
561
core/proxy.go
Normal file
@@ -0,0 +1,561 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
ProxyRuntimeBrowser = "browser"
|
||||
ProxyRuntimeRaw = "raw"
|
||||
ProxyModeOff = "off"
|
||||
ProxyModeTagPool = "tag_pool"
|
||||
DefaultProxyFailureThreshold = 3
|
||||
ProxyOverrideDirect = "direct"
|
||||
)
|
||||
|
||||
var supportedProxySchemes = map[string]struct{}{
|
||||
"http": {},
|
||||
"https": {},
|
||||
"socks5": {},
|
||||
"socks5h": {},
|
||||
}
|
||||
|
||||
var ErrProxyUnavailable = errors.New("proxy unavailable")
|
||||
|
||||
type ProxyPolicy struct {
|
||||
Mode string `json:"mode" mapstructure:"mode"`
|
||||
Tag string `json:"tag,omitempty" mapstructure:"tag"`
|
||||
}
|
||||
|
||||
type ProxyEntryConfig struct {
|
||||
URL string `json:"url" mapstructure:"url"`
|
||||
Tags []string `json:"tags" mapstructure:"tags"`
|
||||
}
|
||||
|
||||
type ProxiesHealthConfig struct {
|
||||
FailureThreshold int `json:"failure_threshold" mapstructure:"failure_threshold"`
|
||||
}
|
||||
|
||||
type ProxiesConfig struct {
|
||||
Global string `json:"global,omitempty" mapstructure:"global"`
|
||||
Entries []ProxyEntryConfig `json:"entries" mapstructure:"entries"`
|
||||
Health ProxiesHealthConfig `json:"health" mapstructure:"health"`
|
||||
}
|
||||
|
||||
type ProxyConfig struct {
|
||||
Runtime string // raw or browser runtime behavior
|
||||
Proxies ProxiesConfig // canonical proxy inventory
|
||||
EnginePolicies map[string]string // engine-specific proxy tags
|
||||
Registry *ProxyRegistry // optional shared registry from caller
|
||||
}
|
||||
|
||||
type ProxyTagSummary struct {
|
||||
Configured int `json:"configured"`
|
||||
Healthy int `json:"healthy"`
|
||||
}
|
||||
|
||||
type ProxyStatsEntry struct {
|
||||
Proxy string `json:"proxy"`
|
||||
Tags []string `json:"tags"`
|
||||
Healthy bool `json:"healthy"`
|
||||
Failures int `json:"failures"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
type ProxyEngineStats struct {
|
||||
Tag string `json:"tag,omitempty"`
|
||||
SelectedProxy string `json:"selected_proxy"`
|
||||
}
|
||||
|
||||
type ProxyStats struct {
|
||||
ConfiguredCount int `json:"configured_count"`
|
||||
HealthyCount int `json:"healthy_count"`
|
||||
UnhealthyCount int `json:"unhealthy_count"`
|
||||
Tags map[string]ProxyTagSummary `json:"tags"`
|
||||
Entries []ProxyStatsEntry `json:"entries"`
|
||||
Engines map[string]ProxyEngineStats `json:"engines,omitempty"`
|
||||
}
|
||||
|
||||
type proxyState struct {
|
||||
url string
|
||||
tags []string
|
||||
failures int
|
||||
disabled bool
|
||||
}
|
||||
|
||||
type ProxyRegistry struct {
|
||||
mu sync.Mutex
|
||||
states map[string]*proxyState
|
||||
order []string
|
||||
tagIndex map[string][]string
|
||||
nextByTag map[string]int
|
||||
failureThreshold int
|
||||
}
|
||||
|
||||
func DefaultProxiesConfig() ProxiesConfig {
|
||||
return ProxiesConfig{
|
||||
Global: "",
|
||||
Entries: []ProxyEntryConfig{},
|
||||
Health: ProxiesHealthConfig{FailureThreshold: DefaultProxyFailureThreshold},
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultProxyConfig() ProxyConfig {
|
||||
return ProxyConfig{
|
||||
Runtime: ProxyRuntimeBrowser,
|
||||
Proxies: DefaultProxiesConfig(),
|
||||
EnginePolicies: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
func NormalizeProxyConfig(cfg ProxyConfig) (ProxyConfig, error) {
|
||||
cfg.Runtime = normalizeProxyRuntime(cfg.Runtime)
|
||||
|
||||
var err error
|
||||
cfg.Proxies, err = NormalizeProxiesConfig(cfg.Proxies)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
if cfg.EnginePolicies == nil {
|
||||
cfg.EnginePolicies = map[string]string{}
|
||||
}
|
||||
normalizedEnginePolicies := make(map[string]string, len(cfg.EnginePolicies))
|
||||
for rawEngine, rawTag := range cfg.EnginePolicies {
|
||||
engine := normalizeEngineName(rawEngine)
|
||||
if engine == "" {
|
||||
continue
|
||||
}
|
||||
tag := normalizeTag(rawTag)
|
||||
if tag == "" {
|
||||
continue
|
||||
}
|
||||
normalizedEnginePolicies[engine] = tag
|
||||
}
|
||||
cfg.EnginePolicies = normalizedEnginePolicies
|
||||
|
||||
if cfg.Registry == nil {
|
||||
if len(cfg.Proxies.Entries) > 0 {
|
||||
registry, err := NewProxyRegistry(cfg.Proxies.Entries, cfg.Proxies.Health.FailureThreshold)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
cfg.Registry = registry
|
||||
}
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func NormalizeProxiesConfig(cfg ProxiesConfig) (ProxiesConfig, error) {
|
||||
global, err := NormalizeProxyURL(cfg.Global)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("invalid proxies.global: %w", err)
|
||||
}
|
||||
cfg.Global = global
|
||||
|
||||
failureThreshold := cfg.Health.FailureThreshold
|
||||
if failureThreshold <= 0 {
|
||||
failureThreshold = DefaultProxyFailureThreshold
|
||||
}
|
||||
|
||||
normalizedEntries := make([]ProxyEntryConfig, 0, len(cfg.Entries))
|
||||
entryByURL := make(map[string]int, len(cfg.Entries))
|
||||
|
||||
for i, rawEntry := range cfg.Entries {
|
||||
proxyURL, err := NormalizeProxyURL(rawEntry.URL)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("invalid proxies.entries[%d].url: %w", i, err)
|
||||
}
|
||||
if proxyURL == "" {
|
||||
return cfg, fmt.Errorf("invalid proxies.entries[%d].url: value is required", i)
|
||||
}
|
||||
|
||||
tags, err := normalizeProxyTags(rawEntry.Tags)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("invalid proxies.entries[%d].tags: %w", i, err)
|
||||
}
|
||||
|
||||
if idx, ok := entryByURL[proxyURL]; ok {
|
||||
normalizedEntries[idx].Tags = mergeTags(normalizedEntries[idx].Tags, tags)
|
||||
continue
|
||||
}
|
||||
|
||||
normalizedEntries = append(normalizedEntries, ProxyEntryConfig{
|
||||
URL: proxyURL,
|
||||
Tags: tags,
|
||||
})
|
||||
entryByURL[proxyURL] = len(normalizedEntries) - 1
|
||||
}
|
||||
|
||||
cfg.Entries = normalizedEntries
|
||||
cfg.Health = ProxiesHealthConfig{FailureThreshold: failureThreshold}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func NormalizeProxyURL(raw string) (string, error) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if parsed.Scheme == "" {
|
||||
return "", fmt.Errorf("proxy URL must include a scheme")
|
||||
}
|
||||
if parsed.Host == "" {
|
||||
return "", fmt.Errorf("proxy URL must include a host")
|
||||
}
|
||||
|
||||
parsed.Scheme = strings.ToLower(parsed.Scheme)
|
||||
if _, ok := supportedProxySchemes[parsed.Scheme]; !ok {
|
||||
return "", fmt.Errorf("unsupported proxy scheme %q", parsed.Scheme)
|
||||
}
|
||||
|
||||
return parsed.String(), nil
|
||||
}
|
||||
|
||||
func NormalizeProxyURLs(rawURLs []string) ([]string, error) {
|
||||
normalized := make([]string, 0, len(rawURLs))
|
||||
seen := make(map[string]struct{}, len(rawURLs))
|
||||
|
||||
for _, raw := range rawURLs {
|
||||
proxyURL, err := NormalizeProxyURL(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if proxyURL == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[proxyURL]; ok {
|
||||
continue
|
||||
}
|
||||
seen[proxyURL] = struct{}{}
|
||||
normalized = append(normalized, proxyURL)
|
||||
}
|
||||
|
||||
return normalized, nil
|
||||
}
|
||||
|
||||
func MaskProxyURL(raw string) string {
|
||||
proxyURL, err := NormalizeProxyURL(raw)
|
||||
if err != nil || proxyURL == "" {
|
||||
return "invalid-proxy"
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(proxyURL)
|
||||
if err != nil {
|
||||
return "invalid-proxy"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host)
|
||||
}
|
||||
|
||||
func ResolveEffectiveProxyPolicy(globalProxyURL string, engineTag string) ProxyPolicy {
|
||||
if strings.TrimSpace(globalProxyURL) != "" {
|
||||
return ProxyPolicy{Mode: ProxyModeTagPool}
|
||||
}
|
||||
|
||||
tag := normalizeTag(engineTag)
|
||||
if tag == "" {
|
||||
return ProxyPolicy{Mode: ProxyModeOff}
|
||||
}
|
||||
|
||||
return ProxyPolicy{Mode: ProxyModeTagPool, Tag: tag}
|
||||
}
|
||||
|
||||
func NormalizeProxyTag(raw string) (string, error) {
|
||||
tag := normalizeTag(raw)
|
||||
if tag == "" {
|
||||
return "", fmt.Errorf("value is required")
|
||||
}
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
func NormalizeProxyRequestOverride(raw string) (string, error) {
|
||||
override := normalizeTag(raw)
|
||||
if override == "" {
|
||||
return "", nil
|
||||
}
|
||||
if override == ProxyOverrideDirect {
|
||||
return ProxyOverrideDirect, nil
|
||||
}
|
||||
return NormalizeProxyTag(override)
|
||||
}
|
||||
|
||||
func IsAuthenticatedSocksProxyURL(raw string) bool {
|
||||
normalized, err := NormalizeProxyURL(raw)
|
||||
if err != nil || normalized == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(normalized)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if (parsed.Scheme == "socks5" || parsed.Scheme == "socks5h") && parsed.User != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func NewProxyRegistry(entries []ProxyEntryConfig, failureThreshold int) (*ProxyRegistry, error) {
|
||||
if failureThreshold <= 0 {
|
||||
failureThreshold = DefaultProxyFailureThreshold
|
||||
}
|
||||
|
||||
states := make(map[string]*proxyState, len(entries))
|
||||
order := make([]string, 0, len(entries))
|
||||
tagIndex := make(map[string][]string)
|
||||
|
||||
for idx, entry := range entries {
|
||||
proxyURL, err := NormalizeProxyURL(entry.URL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid proxy registry entry[%d] url: %w", idx, err)
|
||||
}
|
||||
if proxyURL == "" {
|
||||
return nil, fmt.Errorf("invalid proxy registry entry[%d] url: value is required", idx)
|
||||
}
|
||||
|
||||
tags, err := normalizeProxyTags(entry.Tags)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid proxy registry entry[%d] tags: %w", idx, err)
|
||||
}
|
||||
|
||||
states[proxyURL] = &proxyState{url: proxyURL, tags: tags}
|
||||
order = append(order, proxyURL)
|
||||
for _, tag := range tags {
|
||||
tagIndex[tag] = append(tagIndex[tag], proxyURL)
|
||||
}
|
||||
}
|
||||
|
||||
return &ProxyRegistry{
|
||||
states: states,
|
||||
order: order,
|
||||
tagIndex: tagIndex,
|
||||
nextByTag: make(map[string]int, len(tagIndex)),
|
||||
failureThreshold: failureThreshold,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) NextByTag(tag string) string {
|
||||
tag = normalizeTag(tag)
|
||||
if tag == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
urls := r.tagIndex[tag]
|
||||
if len(urls) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
if r.allDisabledLocked(urls) {
|
||||
logrus.Warnf("Proxy tag pool exhausted for %q, re-enabling tagged proxies", tag)
|
||||
for _, proxyURL := range urls {
|
||||
state := r.states[proxyURL]
|
||||
state.disabled = false
|
||||
state.failures = 0
|
||||
}
|
||||
}
|
||||
|
||||
start := r.nextByTag[tag]
|
||||
for i := 0; i < len(urls); i++ {
|
||||
idx := (start + i) % len(urls)
|
||||
proxyURL := urls[idx]
|
||||
state := r.states[proxyURL]
|
||||
if state.disabled {
|
||||
continue
|
||||
}
|
||||
|
||||
r.nextByTag[tag] = (idx + 1) % len(urls)
|
||||
logrus.Debugf("Selected proxy for tag=%s: %s", tag, MaskProxyURL(proxyURL))
|
||||
return proxyURL
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) ReportFailure(proxyURL string) {
|
||||
proxyURL, err := NormalizeProxyURL(proxyURL)
|
||||
if err != nil || proxyURL == "" {
|
||||
return
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
state, ok := r.states[proxyURL]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
state.failures++
|
||||
if state.failures >= r.failureThreshold {
|
||||
state.disabled = true
|
||||
logrus.Warnf("Disabled proxy after %d failures: %s", state.failures, MaskProxyURL(proxyURL))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) ReportSuccess(proxyURL string) {
|
||||
proxyURL, err := NormalizeProxyURL(proxyURL)
|
||||
if err != nil || proxyURL == "" {
|
||||
return
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
state, ok := r.states[proxyURL]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
state.failures = 0
|
||||
state.disabled = false
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) HasHealthyProxyForTag(tag string) bool {
|
||||
tag = normalizeTag(tag)
|
||||
if tag == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
for _, proxyURL := range r.tagIndex[tag] {
|
||||
if state, ok := r.states[proxyURL]; ok && !state.disabled {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) BuildStats() ProxyStats {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
stats := ProxyStats{
|
||||
Tags: map[string]ProxyTagSummary{},
|
||||
Entries: make([]ProxyStatsEntry, 0, len(r.order)),
|
||||
}
|
||||
|
||||
for _, proxyURL := range r.order {
|
||||
state := r.states[proxyURL]
|
||||
healthy := !state.disabled
|
||||
if healthy {
|
||||
stats.HealthyCount++
|
||||
} else {
|
||||
stats.UnhealthyCount++
|
||||
}
|
||||
stats.ConfiguredCount++
|
||||
|
||||
stats.Entries = append(stats.Entries, ProxyStatsEntry{
|
||||
Proxy: MaskProxyURL(state.url),
|
||||
Tags: append([]string(nil), state.tags...),
|
||||
Healthy: healthy,
|
||||
Failures: state.failures,
|
||||
Disabled: state.disabled,
|
||||
})
|
||||
|
||||
for _, tag := range state.tags {
|
||||
summary := stats.Tags[tag]
|
||||
summary.Configured++
|
||||
if healthy {
|
||||
summary.Healthy++
|
||||
}
|
||||
stats.Tags[tag] = summary
|
||||
}
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
func (r *ProxyRegistry) allDisabledLocked(urls []string) bool {
|
||||
if len(urls) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, proxyURL := range urls {
|
||||
if state, ok := r.states[proxyURL]; ok && !state.disabled {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func normalizeProxyRuntime(runtime string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(runtime)) {
|
||||
case ProxyRuntimeRaw:
|
||||
return ProxyRuntimeRaw
|
||||
default:
|
||||
return ProxyRuntimeBrowser
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeProxyTags(tags []string) ([]string, error) {
|
||||
if len(tags) == 0 {
|
||||
return nil, fmt.Errorf("at least one tag is required")
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(tags))
|
||||
normalized := make([]string, 0, len(tags))
|
||||
for _, rawTag := range tags {
|
||||
tag := normalizeTag(rawTag)
|
||||
if tag == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[tag]; ok {
|
||||
continue
|
||||
}
|
||||
seen[tag] = struct{}{}
|
||||
normalized = append(normalized, tag)
|
||||
}
|
||||
|
||||
if len(normalized) == 0 {
|
||||
return nil, fmt.Errorf("at least one non-empty tag is required")
|
||||
}
|
||||
|
||||
sort.Strings(normalized)
|
||||
return normalized, nil
|
||||
}
|
||||
|
||||
func normalizeTag(raw string) string {
|
||||
return strings.ToLower(strings.TrimSpace(raw))
|
||||
}
|
||||
|
||||
func mergeTags(base []string, additional []string) []string {
|
||||
combined := make(map[string]struct{}, len(base)+len(additional))
|
||||
for _, tag := range base {
|
||||
combined[tag] = struct{}{}
|
||||
}
|
||||
for _, tag := range additional {
|
||||
combined[tag] = struct{}{}
|
||||
}
|
||||
|
||||
merged := make([]string, 0, len(combined))
|
||||
for tag := range combined {
|
||||
merged = append(merged, tag)
|
||||
}
|
||||
sort.Strings(merged)
|
||||
return merged
|
||||
}
|
||||
|
||||
func normalizeEngineName(raw string) string {
|
||||
return strings.ToLower(strings.TrimSpace(raw))
|
||||
}
|
||||
234
core/proxy_integration_test.go
Normal file
234
core/proxy_integration_test.go
Normal file
@@ -0,0 +1,234 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/karust/openserp/testutil"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
const proxyIntegrationEnabledEnv = "OPENSERP_PROXY_TESTS"
|
||||
|
||||
type proxyIntegrationURLs struct {
|
||||
targetURL string
|
||||
socks5hAuthURL string
|
||||
socks5hPlainURL string
|
||||
httpAuthURL string
|
||||
httpPlainURL string
|
||||
badSocks5URL string
|
||||
badHTTPURL string
|
||||
}
|
||||
|
||||
func TestIntegrationSocks5hAuthProxyDNS(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyFetchesTarget(t, cfg.targetURL, cfg.socks5hAuthURL)
|
||||
}
|
||||
|
||||
func TestIntegrationSocks5hPlainProxyDNS(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyFetchesTarget(t, cfg.targetURL, cfg.socks5hPlainURL)
|
||||
}
|
||||
|
||||
func TestIntegrationHTTPAuthProxy(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyFetchesTarget(t, cfg.targetURL, cfg.httpAuthURL)
|
||||
}
|
||||
|
||||
func TestIntegrationHTTPPlainProxy(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyFetchesTarget(t, cfg.targetURL, cfg.httpPlainURL)
|
||||
}
|
||||
|
||||
func TestIntegrationRawSOCKSProxyPoolRotation(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyPoolRotation(t, cfg.targetURL, []string{cfg.badSocks5URL, cfg.socks5hAuthURL})
|
||||
}
|
||||
|
||||
func TestIntegrationRawHTTPProxyPoolRotation(t *testing.T) {
|
||||
cfg := proxyIntegrationConfig(t)
|
||||
assertProxyPoolRotation(t, cfg.targetURL, []string{cfg.badHTTPURL, cfg.httpAuthURL})
|
||||
}
|
||||
|
||||
type proxyIntegrationEngine struct {
|
||||
targetURL string
|
||||
limiter *rate.Limiter
|
||||
proxies []string
|
||||
}
|
||||
|
||||
func (e *proxyIntegrationEngine) Name() string {
|
||||
return "google"
|
||||
}
|
||||
|
||||
func (e *proxyIntegrationEngine) IsInitialized() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *proxyIntegrationEngine) GetRateLimiter() *rate.Limiter {
|
||||
return e.limiter
|
||||
}
|
||||
|
||||
func (e *proxyIntegrationEngine) Search(q Query) ([]SearchResult, error) {
|
||||
e.proxies = append(e.proxies, q.ProxyURL)
|
||||
|
||||
body, err := fetchViaRawProxy(q.ProxyURL, q.Insecure, e.targetURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return []SearchResult{{
|
||||
Rank: 1,
|
||||
URL: e.targetURL,
|
||||
Title: "proxy-ok",
|
||||
Description: body,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (e *proxyIntegrationEngine) SearchImage(q Query) ([]SearchResult, error) {
|
||||
return nil, ErrSearchTimeout
|
||||
}
|
||||
|
||||
func proxyIntegrationConfig(t *testing.T) proxyIntegrationURLs {
|
||||
t.Helper()
|
||||
testutil.RequireIntegration(t)
|
||||
|
||||
if os.Getenv(proxyIntegrationEnabledEnv) != "1" {
|
||||
t.Skipf("set %s=1 to run proxy integration tests", proxyIntegrationEnabledEnv)
|
||||
}
|
||||
|
||||
return proxyIntegrationURLs{
|
||||
targetURL: envOrDefault("OPENSERP_PROXY_TEST_TARGET_URL", "http://proxy-target:8080/"),
|
||||
socks5hAuthURL: envOrDefault("OPENSERP_PROXY_TEST_SOCKS5H_AUTH_URL", "socks5h://test:test@127.0.0.1:19080"),
|
||||
socks5hPlainURL: envOrDefault("OPENSERP_PROXY_TEST_SOCKS5H_PLAIN_URL", "socks5h://127.0.0.1:19082"),
|
||||
httpAuthURL: envOrDefault("OPENSERP_PROXY_TEST_HTTP_AUTH_URL", "http://test:test@127.0.0.1:18888"),
|
||||
httpPlainURL: envOrDefault("OPENSERP_PROXY_TEST_HTTP_PLAIN_URL", "http://127.0.0.1:18889"),
|
||||
badSocks5URL: envOrDefault("OPENSERP_PROXY_TEST_BAD_SOCKS5_URL", "socks5://127.0.0.1:19081"),
|
||||
badHTTPURL: envOrDefault("OPENSERP_PROXY_TEST_BAD_HTTP_URL", "http://127.0.0.1:18890"),
|
||||
}
|
||||
}
|
||||
|
||||
func assertProxyFetchesTarget(t *testing.T, targetURL, proxyURL string) {
|
||||
t.Helper()
|
||||
|
||||
target := mustParseURL(t, targetURL)
|
||||
assertHostCannotResolveTarget(t, target.Hostname())
|
||||
|
||||
body, err := fetchViaRawProxy(proxyURL, false, targetURL)
|
||||
if err != nil {
|
||||
t.Fatalf("expected proxied request via %s to succeed, got %v", proxyURL, err)
|
||||
}
|
||||
if !strings.Contains(body, "proxy-ok") {
|
||||
t.Fatalf("expected proxy target response, got %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
func assertProxyPoolRotation(t *testing.T, targetURL string, pool []string) {
|
||||
t.Helper()
|
||||
|
||||
engine := &proxyIntegrationEngine{
|
||||
targetURL: targetURL,
|
||||
limiter: rate.NewLimiter(rate.Inf, 1),
|
||||
}
|
||||
|
||||
opts := DefaultServerOptions()
|
||||
opts.Resilience.Retry.MaxRetries = 1
|
||||
opts.Resilience.Retry.InitialBackoff = 0
|
||||
opts.Resilience.Retry.MaxBackoff = 0
|
||||
opts.Resilience.Retry.BackoffFactor = 1
|
||||
opts.Resilience.Proxy = ProxyConfig{
|
||||
Runtime: ProxyRuntimeRaw,
|
||||
Proxies: ProxiesConfig{
|
||||
Health: ProxiesHealthConfig{FailureThreshold: 1},
|
||||
},
|
||||
EnginePolicies: map[string]string{"google": "default"},
|
||||
}
|
||||
for _, proxyURL := range pool {
|
||||
opts.Resilience.Proxy.Proxies.Entries = append(opts.Resilience.Proxy.Proxies.Entries, ProxyEntryConfig{
|
||||
URL: proxyURL,
|
||||
Tags: []string{"default"},
|
||||
})
|
||||
}
|
||||
|
||||
srv := NewServerWithOptions("127.0.0.1", 7190, opts, engine)
|
||||
resp := request(t, srv, "/google/search?text=proxy")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("expected rotated proxy request to succeed, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
if len(engine.proxies) != 2 {
|
||||
t.Fatalf("expected 2 proxy attempts, got %d", len(engine.proxies))
|
||||
}
|
||||
if engine.proxies[0] != pool[0] || engine.proxies[1] != pool[1] {
|
||||
t.Fatalf("unexpected proxy rotation order: %#v", engine.proxies)
|
||||
}
|
||||
|
||||
statsResp := request(t, srv, "/stats/proxy")
|
||||
var stats map[string]interface{}
|
||||
if err := json.NewDecoder(statsResp.Body).Decode(&stats); err != nil {
|
||||
t.Fatalf("decode stats: %v", err)
|
||||
}
|
||||
|
||||
if got := stats["healthy_count"].(float64); got != 1 {
|
||||
t.Fatalf("expected healthy_count=1, got %v", got)
|
||||
}
|
||||
if got := stats["unhealthy_count"].(float64); got != 1 {
|
||||
t.Fatalf("expected unhealthy_count=1, got %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func fetchViaRawProxy(proxyURL string, insecure bool, targetURL string) (string, error) {
|
||||
client, err := NewRawHTTPClient(Query{
|
||||
ProxyURL: proxyURL,
|
||||
Insecure: insecure,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp, err := client.Get(targetURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bodyBytes), nil
|
||||
}
|
||||
|
||||
func assertHostCannotResolveTarget(t *testing.T, hostname string) {
|
||||
t.Helper()
|
||||
|
||||
if _, err := net.DefaultResolver.LookupHost(context.Background(), hostname); err == nil {
|
||||
t.Fatalf("expected direct host-side DNS lookup for %q to fail", hostname)
|
||||
}
|
||||
}
|
||||
|
||||
func mustParseURL(t *testing.T, raw string) *url.URL {
|
||||
t.Helper()
|
||||
|
||||
parsed, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("parse target URL %q: %v", raw, err)
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func envOrDefault(key, fallback string) string {
|
||||
if value := strings.TrimSpace(os.Getenv(key)); value != "" {
|
||||
return value
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
345
core/proxy_test.go
Normal file
345
core/proxy_test.go
Normal file
@@ -0,0 +1,345 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
socks5 "github.com/armon/go-socks5"
|
||||
xcontext "golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestNormalizeProxyURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
raw string
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "empty", raw: "", want: ""},
|
||||
{name: "http", raw: "http://127.0.0.1:8080", want: "http://127.0.0.1:8080"},
|
||||
{name: "https", raw: "https://127.0.0.1:8443", want: "https://127.0.0.1:8443"},
|
||||
{name: "socks5", raw: "socks5://127.0.0.1:1080", want: "socks5://127.0.0.1:1080"},
|
||||
{name: "socks5h upper", raw: "SOCKS5H://127.0.0.1:1080", want: "socks5h://127.0.0.1:1080"},
|
||||
{name: "missing scheme", raw: "127.0.0.1:8080", wantErr: true},
|
||||
{name: "missing host", raw: "http://", wantErr: true},
|
||||
{name: "unsupported scheme", raw: "ftp://127.0.0.1:21", wantErr: true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NormalizeProxyURL(tt.raw)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for %q", tt.raw)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Fatalf("expected %q, got %q", tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxiesConfigDefaultsAndDeduplicates(t *testing.T) {
|
||||
cfg, err := NormalizeProxiesConfig(ProxiesConfig{
|
||||
Global: " HTTP://proxy-global:8080 ",
|
||||
Entries: []ProxyEntryConfig{
|
||||
{URL: " http://proxy-one:8080 ", Tags: []string{"default", "us"}},
|
||||
{URL: "http://proxy-one:8080", Tags: []string{"de", "us"}},
|
||||
{URL: "socks5://proxy-two:1080", Tags: []string{"default"}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("normalize proxies config: %v", err)
|
||||
}
|
||||
|
||||
if cfg.Global != "http://proxy-global:8080" {
|
||||
t.Fatalf("expected normalized global proxy, got %q", cfg.Global)
|
||||
}
|
||||
if cfg.Health.FailureThreshold != DefaultProxyFailureThreshold {
|
||||
t.Fatalf("expected default failure threshold %d, got %d", DefaultProxyFailureThreshold, cfg.Health.FailureThreshold)
|
||||
}
|
||||
if len(cfg.Entries) != 2 {
|
||||
t.Fatalf("expected 2 deduplicated entries, got %d", len(cfg.Entries))
|
||||
}
|
||||
if cfg.Entries[0].URL != "http://proxy-one:8080" {
|
||||
t.Fatalf("unexpected normalized URL for first entry: %s", cfg.Entries[0].URL)
|
||||
}
|
||||
if len(cfg.Entries[0].Tags) != 3 {
|
||||
t.Fatalf("expected merged tags in first entry, got %#v", cfg.Entries[0].Tags)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxiesConfigRejectsInvalidEntries(t *testing.T) {
|
||||
_, err := NormalizeProxiesConfig(ProxiesConfig{
|
||||
Entries: []ProxyEntryConfig{{URL: "ftp://proxy:21", Tags: []string{"default"}}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid scheme error")
|
||||
}
|
||||
|
||||
_, err = NormalizeProxiesConfig(ProxiesConfig{
|
||||
Entries: []ProxyEntryConfig{{URL: "http://proxy:8080", Tags: []string{" "}}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected empty tags error")
|
||||
}
|
||||
|
||||
_, err = NormalizeProxiesConfig(ProxiesConfig{
|
||||
Global: "ftp://proxy:21",
|
||||
Entries: []ProxyEntryConfig{{URL: "http://proxy:8080", Tags: []string{"default"}}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid global proxy scheme error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveEffectiveProxyPolicy(t *testing.T) {
|
||||
offPolicy := ResolveEffectiveProxyPolicy("", "")
|
||||
if offPolicy.Mode != ProxyModeOff {
|
||||
t.Fatalf("expected mode off, got %s", offPolicy.Mode)
|
||||
}
|
||||
if offPolicy.Tag != "" {
|
||||
t.Fatalf("expected empty tag for off mode, got %q", offPolicy.Tag)
|
||||
}
|
||||
|
||||
tagOnlyPolicy := ResolveEffectiveProxyPolicy("", "US")
|
||||
if tagOnlyPolicy.Mode != ProxyModeTagPool || tagOnlyPolicy.Tag != "us" {
|
||||
t.Fatalf("unexpected effective policy with tag override: %#v", tagOnlyPolicy)
|
||||
}
|
||||
|
||||
globalPolicy := ResolveEffectiveProxyPolicy("http://proxy-global:8080", "eu")
|
||||
if globalPolicy.Mode != ProxyModeTagPool || globalPolicy.Tag != "" {
|
||||
t.Fatalf("expected global proxy to ignore engine tags, got %#v", globalPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyRegistryRoundRobinAndFailureRecovery(t *testing.T) {
|
||||
registry, err := NewProxyRegistry([]ProxyEntryConfig{
|
||||
{URL: "http://proxy1:8080", Tags: []string{"default"}},
|
||||
{URL: "http://proxy2:8080", Tags: []string{"default"}},
|
||||
}, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("new proxy registry: %v", err)
|
||||
}
|
||||
|
||||
if got := registry.NextByTag("default"); got != "http://proxy1:8080" {
|
||||
t.Fatalf("expected first proxy1, got %s", got)
|
||||
}
|
||||
if got := registry.NextByTag("default"); got != "http://proxy2:8080" {
|
||||
t.Fatalf("expected second proxy2, got %s", got)
|
||||
}
|
||||
|
||||
registry.ReportFailure("http://proxy1:8080")
|
||||
registry.ReportFailure("http://proxy1:8080")
|
||||
if got := registry.NextByTag("default"); got != "http://proxy2:8080" {
|
||||
t.Fatalf("expected proxy2 while proxy1 disabled, got %s", got)
|
||||
}
|
||||
|
||||
registry.ReportFailure("http://proxy2:8080")
|
||||
registry.ReportFailure("http://proxy2:8080")
|
||||
if got := registry.NextByTag("default"); got != "http://proxy1:8080" {
|
||||
t.Fatalf("expected tag pool reset to proxy1 after exhaustion, got %s", got)
|
||||
}
|
||||
|
||||
registry.ReportFailure("http://proxy1:8080")
|
||||
registry.ReportSuccess("http://proxy1:8080")
|
||||
stats := registry.BuildStats()
|
||||
if stats.UnhealthyCount != 0 {
|
||||
t.Fatalf("expected no unhealthy proxies after success recovery, got %d", stats.UnhealthyCount)
|
||||
}
|
||||
if stats.HealthyCount != 2 {
|
||||
t.Fatalf("expected two healthy proxies, got %d", stats.HealthyCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaskProxyURLRedactsCredentials(t *testing.T) {
|
||||
if got := MaskProxyURL("http://user:pass@127.0.0.1:8080"); got != "http://127.0.0.1:8080" {
|
||||
t.Fatalf("unexpected masked proxy value: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyURLForBrowserLaunchStripsCredentials(t *testing.T) {
|
||||
u, err := url.Parse("http://user:pass@127.0.0.1:18888")
|
||||
if err != nil {
|
||||
t.Fatalf("parse proxy URL: %v", err)
|
||||
}
|
||||
|
||||
got := proxyURLForBrowserLaunch(u)
|
||||
want := "http://127.0.0.1:18888"
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyURLForBrowserLaunchNormalizesSocks5h(t *testing.T) {
|
||||
u, err := url.Parse("socks5h://test:test@127.0.0.1:19080")
|
||||
if err != nil {
|
||||
t.Fatalf("parse proxy URL: %v", err)
|
||||
}
|
||||
|
||||
got := proxyURLForBrowserLaunch(u)
|
||||
want := "socks5://127.0.0.1:19080"
|
||||
if got != want {
|
||||
t.Fatalf("expected %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyStatsMaskCredentials(t *testing.T) {
|
||||
registry, err := NewProxyRegistry([]ProxyEntryConfig{
|
||||
{URL: "http://user:pass@proxy.example:8080", Tags: []string{"default"}},
|
||||
}, 1)
|
||||
if err != nil {
|
||||
t.Fatalf("new proxy registry: %v", err)
|
||||
}
|
||||
|
||||
stats := registry.BuildStats()
|
||||
if len(stats.Entries) != 1 {
|
||||
t.Fatalf("expected one proxy stats entry, got %d", len(stats.Entries))
|
||||
}
|
||||
if got := stats.Entries[0].Proxy; got != "http://proxy.example:8080" {
|
||||
t.Fatalf("expected masked proxy in stats, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxyTag(t *testing.T) {
|
||||
tag, err := NormalizeProxyTag(" US ")
|
||||
if err != nil {
|
||||
t.Fatalf("normalize proxy tag: %v", err)
|
||||
}
|
||||
if tag != "us" {
|
||||
t.Fatalf("expected normalized tag us, got %q", tag)
|
||||
}
|
||||
|
||||
if _, err := NormalizeProxyTag(" "); err == nil {
|
||||
t.Fatal("expected empty proxy tag validation error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeProxyRequestOverride(t *testing.T) {
|
||||
override, err := NormalizeProxyRequestOverride(" direct ")
|
||||
if err != nil {
|
||||
t.Fatalf("normalize direct proxy override: %v", err)
|
||||
}
|
||||
if override != ProxyOverrideDirect {
|
||||
t.Fatalf("expected direct override, got %q", override)
|
||||
}
|
||||
|
||||
override, err = NormalizeProxyRequestOverride(" US ")
|
||||
if err != nil {
|
||||
t.Fatalf("normalize tagged proxy override: %v", err)
|
||||
}
|
||||
if override != "us" {
|
||||
t.Fatalf("expected normalized tag override us, got %q", override)
|
||||
}
|
||||
|
||||
override, err = NormalizeProxyRequestOverride("")
|
||||
if err != nil {
|
||||
t.Fatalf("normalize empty override: %v", err)
|
||||
}
|
||||
if override != "" {
|
||||
t.Fatalf("expected empty override, got %q", override)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsAuthenticatedSocksProxyURL(t *testing.T) {
|
||||
if !IsAuthenticatedSocksProxyURL("socks5h://user:pass@127.0.0.1:1080") {
|
||||
t.Fatal("expected authenticated socks proxy to be detected")
|
||||
}
|
||||
if IsAuthenticatedSocksProxyURL("socks5://127.0.0.1:1080") {
|
||||
t.Fatal("expected plain socks proxy to remain browser-compatible")
|
||||
}
|
||||
if IsAuthenticatedSocksProxyURL("http://user:pass@127.0.0.1:8080") {
|
||||
t.Fatal("expected HTTP auth proxy to remain browser-compatible")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRawHTTPClientSocks5hUsesProxyDNS(t *testing.T) {
|
||||
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("proxied"))
|
||||
}))
|
||||
defer target.Close()
|
||||
|
||||
targetAddr, err := net.ResolveTCPAddr("tcp", target.Listener.Addr().String())
|
||||
if err != nil {
|
||||
t.Fatalf("resolve target listener: %v", err)
|
||||
}
|
||||
|
||||
const proxyOnlyHost = "proxy-target.invalid"
|
||||
proxyAddr := startSOCKS5TestServer(t, proxyOnlyHost, targetAddr.IP)
|
||||
|
||||
directClient := &http.Client{Timeout: 500 * time.Millisecond}
|
||||
targetURL := fmt.Sprintf("http://%s:%d/", proxyOnlyHost, targetAddr.Port)
|
||||
if _, err := directClient.Get(targetURL); err == nil {
|
||||
t.Fatal("expected direct request to fail without proxy DNS")
|
||||
}
|
||||
|
||||
client, err := NewRawHTTPClient(Query{ProxyURL: "socks5h://" + proxyAddr})
|
||||
if err != nil {
|
||||
t.Fatalf("new raw http client: %v", err)
|
||||
}
|
||||
|
||||
resp, err := client.Get(targetURL)
|
||||
if err != nil {
|
||||
t.Fatalf("expected proxied request to succeed, got %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("read proxied body: %v", err)
|
||||
}
|
||||
if string(body) != "proxied" {
|
||||
t.Fatalf("unexpected proxied body: %q", string(body))
|
||||
}
|
||||
}
|
||||
|
||||
type staticResolver struct {
|
||||
host string
|
||||
ip net.IP
|
||||
}
|
||||
|
||||
func (r staticResolver) Resolve(ctx xcontext.Context, name string) (xcontext.Context, net.IP, error) {
|
||||
if name == r.host {
|
||||
return ctx, r.ip, nil
|
||||
}
|
||||
return ctx, nil, net.UnknownNetworkError(name)
|
||||
}
|
||||
|
||||
func startSOCKS5TestServer(t *testing.T, host string, ip net.IP) string {
|
||||
t.Helper()
|
||||
|
||||
server, err := socks5.New(&socks5.Config{
|
||||
Resolver: staticResolver{host: host, ip: ip},
|
||||
Logger: log.New(io.Discard, "", 0),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create socks5 server: %v", err)
|
||||
}
|
||||
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatalf("listen socks5: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
_ = listener.Close()
|
||||
})
|
||||
|
||||
go func() {
|
||||
_ = server.Serve(listener)
|
||||
}()
|
||||
|
||||
return listener.Addr().String()
|
||||
}
|
||||
436
core/resilient.go
Normal file
436
core/resilient.go
Normal file
@@ -0,0 +1,436 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ResilientSearcher wraps engines with retry and circuit breaker protection.
|
||||
type ResilientSearcher struct {
|
||||
engines []SearchEngine
|
||||
cbManager *CircuitBreakerManager
|
||||
retryCfg RetryConfig
|
||||
|
||||
proxyRuntime string
|
||||
proxyCfg ProxyConfig
|
||||
proxyRegistry *ProxyRegistry
|
||||
proxyDefaults ProxyPolicy
|
||||
|
||||
effectivePolicies map[string]ProxyPolicy
|
||||
}
|
||||
|
||||
type ProxyExecutionMeta struct {
|
||||
Mode string `json:"mode"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Used string `json:"used"`
|
||||
}
|
||||
|
||||
type ResilientConfig struct {
|
||||
Retry RetryConfig
|
||||
CircuitBreaker CircuitBreakerConfig
|
||||
Proxy ProxyConfig
|
||||
}
|
||||
|
||||
func DefaultResilientConfig() ResilientConfig {
|
||||
return ResilientConfig{
|
||||
Retry: DefaultRetryConfig(),
|
||||
CircuitBreaker: DefaultCircuitBreakerConfig(),
|
||||
Proxy: DefaultProxyConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewResilientSearcher(engines []SearchEngine, cfg ResilientConfig) *ResilientSearcher {
|
||||
proxyCfg, err := NormalizeProxyConfig(cfg.Proxy)
|
||||
if err != nil {
|
||||
logrus.Errorf("Invalid proxy config, using defaults: %v", err)
|
||||
proxyCfg = DefaultProxyConfig()
|
||||
proxyCfg, _ = NormalizeProxyConfig(proxyCfg)
|
||||
}
|
||||
|
||||
rs := &ResilientSearcher{
|
||||
engines: engines,
|
||||
cbManager: NewCircuitBreakerManager(cfg.CircuitBreaker),
|
||||
retryCfg: cfg.Retry,
|
||||
proxyRuntime: proxyCfg.Runtime,
|
||||
proxyCfg: proxyCfg,
|
||||
proxyRegistry: proxyCfg.Registry,
|
||||
proxyDefaults: ResolveEffectiveProxyPolicy(proxyCfg.Proxies.Global, ""),
|
||||
effectivePolicies: make(map[string]ProxyPolicy, len(engines)),
|
||||
}
|
||||
|
||||
for _, engine := range engines {
|
||||
engineName := normalizeEngineName(engine.Name())
|
||||
override := proxyCfg.EnginePolicies[engineName]
|
||||
effective := ResolveEffectiveProxyPolicy(proxyCfg.Proxies.Global, override)
|
||||
rs.effectivePolicies[engineName] = effective
|
||||
}
|
||||
|
||||
return rs
|
||||
}
|
||||
|
||||
// SearchPrimary keeps dedicated endpoints engine-pure (no fallback).
|
||||
func (rs *ResilientSearcher) SearchPrimary(primaryEngine SearchEngine, q Query) ([]SearchResult, string, ProxyExecutionMeta, error) {
|
||||
results, proxyMeta, err := rs.searchWithProtection(primaryEngine, q, false)
|
||||
if err != nil {
|
||||
return nil, primaryEngine.Name(), proxyMeta, err
|
||||
}
|
||||
return results, primaryEngine.Name(), proxyMeta, nil
|
||||
}
|
||||
|
||||
// SearchWithFallback retries primary and then tries other initialized engines.
|
||||
func (rs *ResilientSearcher) SearchWithFallback(primaryEngine SearchEngine, q Query) ([]SearchResult, string, ProxyExecutionMeta, error) {
|
||||
return rs.searchWithFallback(primaryEngine, q, false)
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) SearchImagePrimary(primaryEngine SearchEngine, q Query) ([]SearchResult, string, ProxyExecutionMeta, error) {
|
||||
results, proxyMeta, err := rs.searchWithProtection(primaryEngine, q, true)
|
||||
if err != nil {
|
||||
return nil, primaryEngine.Name(), proxyMeta, err
|
||||
}
|
||||
return results, primaryEngine.Name(), proxyMeta, nil
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) SearchImageWithFallback(primaryEngine SearchEngine, q Query) ([]SearchResult, string, ProxyExecutionMeta, error) {
|
||||
return rs.searchWithFallback(primaryEngine, q, true)
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) searchWithFallback(primaryEngine SearchEngine, q Query, isImage bool) ([]SearchResult, string, ProxyExecutionMeta, error) {
|
||||
results, proxyMeta, err := rs.searchWithProtection(primaryEngine, q, isImage)
|
||||
if err == nil {
|
||||
return results, primaryEngine.Name(), proxyMeta, nil
|
||||
}
|
||||
if errors.Is(err, ErrProxyUnavailable) {
|
||||
logrus.Warnf("[Resilient] Primary engine %s proxy policy failed closed: %s", primaryEngine.Name(), err)
|
||||
return nil, primaryEngine.Name(), proxyMeta, err
|
||||
}
|
||||
|
||||
action := "failed"
|
||||
successMessage := "Fallback to %s succeeded with %d results"
|
||||
if isImage {
|
||||
action = "image search failed"
|
||||
successMessage = "Image fallback to %s succeeded with %d results"
|
||||
}
|
||||
|
||||
logrus.Warnf("[Resilient] Primary engine %s %s: %s. Trying fallback engines...", primaryEngine.Name(), action, err)
|
||||
for _, fallbackEngine := range rs.engines {
|
||||
if fallbackEngine.Name() == primaryEngine.Name() || !fallbackEngine.IsInitialized() {
|
||||
continue
|
||||
}
|
||||
|
||||
results, fallbackMeta, fallbackErr := rs.searchWithProtection(fallbackEngine, q, isImage)
|
||||
if fallbackErr == nil {
|
||||
logrus.Infof("[Resilient] "+successMessage, fallbackEngine.Name(), len(results))
|
||||
return results, fallbackEngine.Name(), fallbackMeta, nil
|
||||
}
|
||||
logrus.Warnf("[Resilient] Fallback engine %s also failed: %s", fallbackEngine.Name(), fallbackErr)
|
||||
}
|
||||
|
||||
return nil, primaryEngine.Name(), proxyMeta, ErrAllEnginesFailed
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) searchWithProtection(engine SearchEngine, q Query, isImage bool) ([]SearchResult, ProxyExecutionMeta, error) {
|
||||
cb := rs.cbManager.Get(engine.Name())
|
||||
if !cb.AllowRequest() {
|
||||
return nil, ProxyExecutionMeta{}, ErrCircuitOpen
|
||||
}
|
||||
|
||||
policy := rs.effectivePolicyForQuery(engine.Name(), q)
|
||||
attemptMeta := rs.baseProxyMeta(policy)
|
||||
|
||||
result := RetryableSearch(rs.retryCfg, engine.Name(), func() ([]SearchResult, error) {
|
||||
limiter := engine.GetRateLimiter()
|
||||
if limiter != nil {
|
||||
if err := limiter.Wait(context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
attemptQuery := q
|
||||
proxyURL := ""
|
||||
reportToRegistry := false
|
||||
attemptMeta = rs.baseProxyMeta(policy)
|
||||
|
||||
switch policy.Mode {
|
||||
case ProxyModeOff:
|
||||
attemptQuery.ProxyURL = ""
|
||||
attemptMeta.Used = "direct"
|
||||
case ProxyModeTagPool:
|
||||
proxyURL = rs.selectProxyForQuery(policy, q)
|
||||
if proxyURL == "" {
|
||||
return nil, fmt.Errorf("%w: no healthy proxy available for tag %q", ErrProxyUnavailable, policy.Tag)
|
||||
}
|
||||
attemptQuery.ProxyURL = proxyURL
|
||||
reportToRegistry = policy.Tag != ""
|
||||
attemptMeta.Used = MaskProxyURL(proxyURL)
|
||||
}
|
||||
|
||||
var (
|
||||
results []SearchResult
|
||||
err error
|
||||
)
|
||||
if isImage {
|
||||
results, err = engine.SearchImage(attemptQuery)
|
||||
} else {
|
||||
results, err = engine.Search(attemptQuery)
|
||||
}
|
||||
|
||||
if reportToRegistry {
|
||||
rs.reportProxyAttempt(proxyURL, err)
|
||||
}
|
||||
|
||||
return results, err
|
||||
})
|
||||
|
||||
if result.Err != nil {
|
||||
if !errors.Is(result.Err, ErrProxyUnavailable) {
|
||||
cb.RecordFailure()
|
||||
}
|
||||
return nil, attemptMeta, result.Err
|
||||
}
|
||||
|
||||
cb.RecordSuccess()
|
||||
return result.Results, attemptMeta, nil
|
||||
}
|
||||
|
||||
// SearchAllParallel applies retry/circuit protections per engine for mega search.
|
||||
func (rs *ResilientSearcher) SearchAllParallel(q Query, engines []SearchEngine) []MegaSearchResult {
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
var allResults []MegaSearchResult
|
||||
|
||||
for _, engine := range engines {
|
||||
if !engine.IsInitialized() {
|
||||
continue
|
||||
}
|
||||
if !rs.cbManager.Get(engine.Name()).AllowRequest() {
|
||||
logrus.Infof("[Resilient] Skipping %s in megasearch (circuit open)", engine.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(eng SearchEngine) {
|
||||
defer wg.Done()
|
||||
|
||||
results, _, err := rs.searchWithProtection(eng, q, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
for _, r := range results {
|
||||
allResults = append(allResults, MegaSearchResult{
|
||||
SearchResult: r,
|
||||
Engine: eng.Name(),
|
||||
})
|
||||
}
|
||||
mu.Unlock()
|
||||
}(engine)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return allResults
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) SearchAllImageParallel(q Query, engines []SearchEngine) []MegaSearchResult {
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
var allResults []MegaSearchResult
|
||||
|
||||
for _, engine := range engines {
|
||||
if !engine.IsInitialized() {
|
||||
continue
|
||||
}
|
||||
if !rs.cbManager.Get(engine.Name()).AllowRequest() {
|
||||
logrus.Infof("[Resilient] Skipping %s in megaimage (circuit open)", engine.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func(eng SearchEngine) {
|
||||
defer wg.Done()
|
||||
|
||||
results, _, err := rs.searchWithProtection(eng, q, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
for _, r := range results {
|
||||
allResults = append(allResults, MegaSearchResult{
|
||||
SearchResult: r,
|
||||
Engine: eng.Name(),
|
||||
})
|
||||
}
|
||||
mu.Unlock()
|
||||
}(engine)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return allResults
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) GetCircuitBreakerStats() []map[string]interface{} {
|
||||
return rs.cbManager.AllStats()
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) GetProxyStats() ProxyStats {
|
||||
stats := ProxyStats{
|
||||
ConfiguredCount: 0,
|
||||
HealthyCount: 0,
|
||||
UnhealthyCount: 0,
|
||||
Tags: map[string]ProxyTagSummary{},
|
||||
Entries: []ProxyStatsEntry{},
|
||||
}
|
||||
|
||||
if rs.proxyRegistry != nil {
|
||||
stats = rs.proxyRegistry.BuildStats()
|
||||
}
|
||||
|
||||
engines := map[string]ProxyEngineStats{}
|
||||
for _, engine := range rs.engines {
|
||||
engineName := normalizeEngineName(engine.Name())
|
||||
policy := rs.effectivePolicyForEngine(engineName)
|
||||
engineStats := ProxyEngineStats{}
|
||||
|
||||
switch policy.Mode {
|
||||
case ProxyModeOff:
|
||||
engineStats.SelectedProxy = "direct"
|
||||
case ProxyModeTagPool:
|
||||
engineStats.Tag = policy.Tag
|
||||
if global := strings.TrimSpace(rs.proxyCfg.Proxies.Global); global != "" {
|
||||
engineStats.SelectedProxy = MaskProxyURL(global)
|
||||
} else {
|
||||
engineStats.SelectedProxy = "pooled"
|
||||
}
|
||||
}
|
||||
|
||||
engines[engineName] = engineStats
|
||||
}
|
||||
if len(engines) > 0 {
|
||||
stats.Engines = engines
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) ResolveMegaProxyMeta(q Query, engines []SearchEngine) ProxyExecutionMeta {
|
||||
if len(engines) == 0 {
|
||||
return ProxyExecutionMeta{Mode: ProxyModeOff, Used: "direct"}
|
||||
}
|
||||
|
||||
allOff := true
|
||||
proxiedTags := map[string]struct{}{}
|
||||
hasOff := false
|
||||
|
||||
for _, engine := range engines {
|
||||
policy := rs.effectivePolicyForQuery(engine.Name(), q)
|
||||
if policy.Mode == ProxyModeOff {
|
||||
hasOff = true
|
||||
continue
|
||||
}
|
||||
|
||||
allOff = false
|
||||
if policy.Tag != "" {
|
||||
proxiedTags[policy.Tag] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
if allOff {
|
||||
return ProxyExecutionMeta{Mode: ProxyModeOff, Used: "direct"}
|
||||
}
|
||||
|
||||
meta := ProxyExecutionMeta{Mode: ProxyModeTagPool}
|
||||
if len(proxiedTags) == 1 {
|
||||
for tag := range proxiedTags {
|
||||
meta.Tag = tag
|
||||
}
|
||||
}
|
||||
|
||||
if q.ProxyOverride == "" {
|
||||
if global := strings.TrimSpace(rs.proxyCfg.Proxies.Global); global != "" && !hasOff {
|
||||
meta.Used = MaskProxyURL(global)
|
||||
return meta
|
||||
}
|
||||
}
|
||||
|
||||
if rs.proxyRuntime == ProxyRuntimeRaw {
|
||||
meta.Used = "multiple"
|
||||
if hasOff {
|
||||
meta.Used = "mixed"
|
||||
}
|
||||
return meta
|
||||
}
|
||||
meta.Used = "multiple"
|
||||
if hasOff {
|
||||
meta.Used = "mixed"
|
||||
}
|
||||
return meta
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) baseProxyMeta(policy ProxyPolicy) ProxyExecutionMeta {
|
||||
meta := ProxyExecutionMeta{Mode: policy.Mode}
|
||||
if policy.Mode == ProxyModeTagPool {
|
||||
meta.Tag = policy.Tag
|
||||
return meta
|
||||
}
|
||||
meta.Used = "direct"
|
||||
return meta
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) effectivePolicyForEngine(engineName string) ProxyPolicy {
|
||||
engineName = normalizeEngineName(engineName)
|
||||
if policy, ok := rs.effectivePolicies[engineName]; ok {
|
||||
return policy
|
||||
}
|
||||
return rs.proxyDefaults
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) effectivePolicyForQuery(engineName string, q Query) ProxyPolicy {
|
||||
switch q.ProxyOverride {
|
||||
case "":
|
||||
return rs.effectivePolicyForEngine(engineName)
|
||||
case ProxyOverrideDirect:
|
||||
return ProxyPolicy{Mode: ProxyModeOff}
|
||||
default:
|
||||
return ProxyPolicy{Mode: ProxyModeTagPool, Tag: q.ProxyOverride}
|
||||
}
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) selectProxyForTag(tag string) string {
|
||||
if rs.proxyRegistry == nil {
|
||||
return ""
|
||||
}
|
||||
return rs.proxyRegistry.NextByTag(tag)
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) reportProxyAttempt(proxyURL string, err error) {
|
||||
if rs.proxyRegistry == nil || proxyURL == "" {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
rs.proxyRegistry.ReportFailure(proxyURL)
|
||||
return
|
||||
}
|
||||
|
||||
rs.proxyRegistry.ReportSuccess(proxyURL)
|
||||
}
|
||||
|
||||
func (rs *ResilientSearcher) selectProxyForQuery(policy ProxyPolicy, q Query) string {
|
||||
if policy.Mode != ProxyModeTagPool {
|
||||
return ""
|
||||
}
|
||||
if q.ProxyOverride == "" {
|
||||
if global := strings.TrimSpace(rs.proxyCfg.Proxies.Global); global != "" {
|
||||
return global
|
||||
}
|
||||
}
|
||||
return rs.selectProxyForTag(policy.Tag)
|
||||
}
|
||||
|
||||
var ErrAllEnginesFailed = fmt.Errorf("all search engines failed")
|
||||
100
core/retry.go
Normal file
100
core/retry.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RetryConfig controls retry behavior.
|
||||
type RetryConfig struct {
|
||||
MaxRetries int
|
||||
InitialBackoff time.Duration
|
||||
MaxBackoff time.Duration
|
||||
BackoffFactor float64
|
||||
}
|
||||
|
||||
func DefaultRetryConfig() RetryConfig {
|
||||
return RetryConfig{
|
||||
MaxRetries: 3,
|
||||
InitialBackoff: time.Second,
|
||||
MaxBackoff: 30 * time.Second,
|
||||
BackoffFactor: 2.0,
|
||||
}
|
||||
}
|
||||
|
||||
type RetryResult struct {
|
||||
Results []SearchResult
|
||||
Err error
|
||||
Attempts int
|
||||
Engine string
|
||||
}
|
||||
|
||||
// RetryableSearch executes searchFn with exponential backoff retries.
|
||||
// CAPTCHA and proxy-unavailable errors are not retried.
|
||||
func RetryableSearch(cfg RetryConfig, engineName string, searchFn func() ([]SearchResult, error)) RetryResult {
|
||||
if cfg.BackoffFactor <= 0 {
|
||||
cfg.BackoffFactor = 2.0
|
||||
}
|
||||
|
||||
var lastErr error
|
||||
for attempt := 0; attempt <= cfg.MaxRetries; attempt++ {
|
||||
if attempt > 0 {
|
||||
backoff := calculateBackoff(cfg, attempt)
|
||||
logrus.Warnf("[%s] Retry attempt %d/%d after %s", engineName, attempt, cfg.MaxRetries, backoff)
|
||||
time.Sleep(backoff)
|
||||
}
|
||||
|
||||
results, err := searchFn()
|
||||
if err == nil {
|
||||
if attempt > 0 {
|
||||
logrus.Infof("[%s] Succeeded on retry attempt %d", engineName, attempt)
|
||||
}
|
||||
return RetryResult{
|
||||
Results: results,
|
||||
Attempts: attempt + 1,
|
||||
Engine: engineName,
|
||||
}
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
if errors.Is(err, ErrCaptcha) {
|
||||
logrus.Warnf("[%s] CAPTCHA detected, skipping retries", engineName)
|
||||
return RetryResult{
|
||||
Err: err,
|
||||
Attempts: attempt + 1,
|
||||
Engine: engineName,
|
||||
}
|
||||
}
|
||||
if errors.Is(err, ErrProxyUnavailable) {
|
||||
logrus.Warnf("[%s] Proxy unavailable, skipping retries", engineName)
|
||||
return RetryResult{
|
||||
Err: err,
|
||||
Attempts: attempt + 1,
|
||||
Engine: engineName,
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Warnf("[%s] Attempt %d failed: %s", engineName, attempt+1, err)
|
||||
}
|
||||
|
||||
return RetryResult{
|
||||
Err: fmt.Errorf("all %d attempts failed for %s: %w", cfg.MaxRetries+1, engineName, lastErr),
|
||||
Attempts: cfg.MaxRetries + 1,
|
||||
Engine: engineName,
|
||||
}
|
||||
}
|
||||
|
||||
func calculateBackoff(cfg RetryConfig, attempt int) time.Duration {
|
||||
backoff := float64(cfg.InitialBackoff) * math.Pow(cfg.BackoffFactor, float64(attempt-1))
|
||||
if backoff > float64(cfg.MaxBackoff) {
|
||||
backoff = float64(cfg.MaxBackoff)
|
||||
}
|
||||
if backoff < 0 {
|
||||
backoff = 0
|
||||
}
|
||||
return time.Duration(backoff)
|
||||
}
|
||||
86
core/retry_test.go
Normal file
86
core/retry_test.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRetryableSearch_SuccessOnFirstAttempt(t *testing.T) {
|
||||
cfg := RetryConfig{MaxRetries: 3, InitialBackoff: 10 * time.Millisecond, MaxBackoff: 100 * time.Millisecond, BackoffFactor: 2.0}
|
||||
calls := 0
|
||||
|
||||
result := RetryableSearch(cfg, "test", func() ([]SearchResult, error) {
|
||||
calls++
|
||||
return []SearchResult{{Title: "result1"}}, nil
|
||||
})
|
||||
|
||||
if result.Err != nil {
|
||||
t.Fatalf("expected no error, got: %v", result.Err)
|
||||
}
|
||||
if result.Attempts != 1 {
|
||||
t.Errorf("expected 1 attempt, got: %d", result.Attempts)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Errorf("expected 1 call, got: %d", calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryableSearch_AllAttemptsFail(t *testing.T) {
|
||||
cfg := RetryConfig{MaxRetries: 2, InitialBackoff: 10 * time.Millisecond, MaxBackoff: 50 * time.Millisecond, BackoffFactor: 2.0}
|
||||
calls := 0
|
||||
|
||||
result := RetryableSearch(cfg, "test", func() ([]SearchResult, error) {
|
||||
calls++
|
||||
return nil, errors.New("persistent failure")
|
||||
})
|
||||
|
||||
if result.Err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if calls != 3 {
|
||||
t.Errorf("expected 3 calls (1 + 2 retries), got: %d", calls)
|
||||
}
|
||||
if result.Attempts != 3 {
|
||||
t.Errorf("expected 3 attempts, got: %d", result.Attempts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryableSearch_CaptchaNotRetried(t *testing.T) {
|
||||
cfg := RetryConfig{MaxRetries: 3, InitialBackoff: 10 * time.Millisecond, MaxBackoff: 100 * time.Millisecond, BackoffFactor: 2.0}
|
||||
calls := 0
|
||||
|
||||
result := RetryableSearch(cfg, "test", func() ([]SearchResult, error) {
|
||||
calls++
|
||||
return nil, ErrCaptcha
|
||||
})
|
||||
|
||||
if !errors.Is(result.Err, ErrCaptcha) {
|
||||
t.Fatalf("expected ErrCaptcha, got: %v", result.Err)
|
||||
}
|
||||
if calls != 1 {
|
||||
t.Errorf("expected 1 call, got: %d", calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateBackoff(t *testing.T) {
|
||||
cfg := RetryConfig{InitialBackoff: 1 * time.Second, MaxBackoff: 10 * time.Second, BackoffFactor: 2.0}
|
||||
|
||||
tests := []struct {
|
||||
attempt int
|
||||
expected time.Duration
|
||||
}{
|
||||
{1, 1 * time.Second},
|
||||
{2, 2 * time.Second},
|
||||
{3, 4 * time.Second},
|
||||
{4, 8 * time.Second},
|
||||
{5, 10 * time.Second},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := calculateBackoff(cfg, tt.attempt)
|
||||
if got != tt.expected {
|
||||
t.Errorf("attempt %d: expected %s, got %s", tt.attempt, tt.expected, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
591
core/server.go
591
core/server.go
@@ -1,9 +1,13 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -19,89 +23,546 @@ type SearchEngine interface {
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
app *fiber.App
|
||||
addr string
|
||||
app *fiber.App
|
||||
addr string
|
||||
searchEngines []SearchEngine
|
||||
cache *ResponseCache
|
||||
resilient *ResilientSearcher
|
||||
startTime time.Time
|
||||
opts ServerOptions
|
||||
}
|
||||
|
||||
type ServerOptions struct {
|
||||
CacheTTL time.Duration
|
||||
CacheMaxSize int
|
||||
EnableCORS bool
|
||||
CORS CORSConfig
|
||||
AllowEndpointFallback bool
|
||||
Resilience ResilientConfig
|
||||
}
|
||||
|
||||
func DefaultServerOptions() ServerOptions {
|
||||
return ServerOptions{
|
||||
CacheTTL: 5 * time.Minute,
|
||||
CacheMaxSize: 1000,
|
||||
EnableCORS: true,
|
||||
CORS: DefaultCORSConfig(),
|
||||
AllowEndpointFallback: false,
|
||||
Resilience: DefaultResilientConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewServer(host string, port int, searchEngines ...SearchEngine) *Server {
|
||||
return NewServerWithOptions(host, port, DefaultServerOptions(), searchEngines...)
|
||||
}
|
||||
|
||||
func NewServerWithOptions(host string, port int, opts ServerOptions, searchEngines ...SearchEngine) *Server {
|
||||
addr := fmt.Sprintf("%s:%d", host, port)
|
||||
app := fiber.New(fiber.Config{
|
||||
ErrorHandler: JSONErrorMiddleware(),
|
||||
})
|
||||
|
||||
serv := Server{
|
||||
app: fiber.New(),
|
||||
addr: addr,
|
||||
app: app,
|
||||
addr: addr,
|
||||
searchEngines: searchEngines,
|
||||
resilient: NewResilientSearcher(searchEngines, opts.Resilience),
|
||||
startTime: time.Now(),
|
||||
opts: opts,
|
||||
}
|
||||
logrus.Info("Resilient search enabled: retry + circuit breaker")
|
||||
if opts.AllowEndpointFallback {
|
||||
logrus.Warn("Dedicated endpoint fallback is enabled")
|
||||
}
|
||||
if opts.CacheTTL > 0 && opts.CacheMaxSize > 0 {
|
||||
serv.cache = NewResponseCache(opts.CacheTTL, opts.CacheMaxSize)
|
||||
logrus.Infof("Response cache enabled: TTL=%s, MaxSize=%d", opts.CacheTTL, opts.CacheMaxSize)
|
||||
}
|
||||
|
||||
if opts.EnableCORS {
|
||||
app.Use(CORSMiddleware(opts.CORS))
|
||||
}
|
||||
app.Use(RequestLoggerMiddleware())
|
||||
|
||||
app.Get("/health", serv.handleHealthCheck)
|
||||
app.Get("/stats", serv.handleStats)
|
||||
app.Get("/stats/cache", serv.handleCacheStats)
|
||||
app.Get("/stats/proxy", serv.handleProxyStats)
|
||||
app.Get("/stats/cb", serv.handleCircuitBreakerStats)
|
||||
|
||||
for _, engine := range searchEngines {
|
||||
locEngine := engine
|
||||
limiter := engine.GetRateLimiter()
|
||||
|
||||
serv.app.Get(fmt.Sprintf("/%s/search", strings.ToLower(locEngine.Name())), func(c *fiber.Ctx) error {
|
||||
q := Query{}
|
||||
err := q.InitFromContext(c)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error while setting %s query: %s", locEngine.Name(), err)
|
||||
return err
|
||||
}
|
||||
endpointName := strings.ToLower(locEngine.Name())
|
||||
if endpointName == "duckduckgo" {
|
||||
endpointName = "duck"
|
||||
}
|
||||
|
||||
err = limiter.Wait(context.Background())
|
||||
if err != nil {
|
||||
logrus.Errorf("Ratelimiter error during %s query: %s", locEngine.Name(), err)
|
||||
}
|
||||
|
||||
res, err := locEngine.Search(q)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case ErrCaptcha:
|
||||
err = fmt.Errorf("captcha found, please stop sending requests for a while\n%s", err)
|
||||
case ErrSearchTimeout:
|
||||
err = fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
logrus.Errorf("Error during %s search: %s", locEngine.Name(), err)
|
||||
return fiber.NewError(fiber.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(res)
|
||||
serv.app.Get(fmt.Sprintf("/%s/search", endpointName), func(c *fiber.Ctx) error {
|
||||
return serv.handleDedicatedEndpoint(c, locEngine, false)
|
||||
})
|
||||
|
||||
serv.app.Get(fmt.Sprintf("/%s/image", strings.ToLower(locEngine.Name())), func(c *fiber.Ctx) error {
|
||||
q := Query{}
|
||||
err := q.InitFromContext(c)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error while setting %s query: %s", locEngine.Name(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = limiter.Wait(context.Background())
|
||||
if err != nil {
|
||||
logrus.Errorf("Ratelimiter error during %s query: %s", locEngine.Name(), err)
|
||||
}
|
||||
|
||||
res, err := locEngine.SearchImage(q)
|
||||
|
||||
if err != nil && len(res) > 0 {
|
||||
c.Status(503)
|
||||
return c.JSON(res)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
switch err {
|
||||
case ErrCaptcha:
|
||||
err = fmt.Errorf("captcha found, please stop sending requests for a while: %s", err)
|
||||
case ErrSearchTimeout:
|
||||
err = fmt.Errorf("%s", err)
|
||||
}
|
||||
|
||||
logrus.Errorf("Error during %s search: %s", locEngine.Name(), err)
|
||||
return fiber.NewError(fiber.StatusServiceUnavailable, err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(res)
|
||||
serv.app.Get(fmt.Sprintf("/%s/image", endpointName), func(c *fiber.Ctx) error {
|
||||
return serv.handleDedicatedEndpoint(c, locEngine, true)
|
||||
})
|
||||
}
|
||||
|
||||
serv.app.Get("/mega/search", serv.handleMegaSearch)
|
||||
serv.app.Get("/mega/image", serv.handleMegaImage)
|
||||
serv.app.Get("/mega/engines", serv.handleListEngines)
|
||||
|
||||
return &serv
|
||||
}
|
||||
|
||||
func (s *Server) handleDedicatedEndpoint(c *fiber.Ctx, engine SearchEngine, isImage bool) error {
|
||||
q := Query{}
|
||||
if err := q.InitFromContext(c); err != nil {
|
||||
logrus.Errorf("Error while setting %s query: %s", engine.Name(), err)
|
||||
return err
|
||||
}
|
||||
|
||||
action := "search"
|
||||
if isImage {
|
||||
action = "image"
|
||||
}
|
||||
logrus.Infof("Starting SERP %s request using %s engine for query: %s", action, engine.Name(), q.Text)
|
||||
|
||||
if hit, err := s.tryServeCacheHit(
|
||||
c,
|
||||
cacheHitCandidate{
|
||||
key: BuildCacheKey(engine.Name(), action, q),
|
||||
logMessage: fmt.Sprintf("Cache hit for %s %s: %s", engine.Name(), action, q.Text),
|
||||
},
|
||||
); hit || err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
res []SearchResult
|
||||
usedEngine string
|
||||
proxyMeta ProxyExecutionMeta
|
||||
searchErr error
|
||||
)
|
||||
|
||||
if isImage {
|
||||
if s.opts.AllowEndpointFallback {
|
||||
res, usedEngine, proxyMeta, searchErr = s.resilient.SearchImageWithFallback(engine, q)
|
||||
} else {
|
||||
res, usedEngine, proxyMeta, searchErr = s.resilient.SearchImagePrimary(engine, q)
|
||||
}
|
||||
} else {
|
||||
if s.opts.AllowEndpointFallback {
|
||||
res, usedEngine, proxyMeta, searchErr = s.resilient.SearchWithFallback(engine, q)
|
||||
} else {
|
||||
res, usedEngine, proxyMeta, searchErr = s.resilient.SearchPrimary(engine, q)
|
||||
}
|
||||
}
|
||||
s.applyProxyHeaders(c, proxyMeta)
|
||||
|
||||
if searchErr != nil {
|
||||
errToReturn := searchErr
|
||||
switch searchErr {
|
||||
case ErrCaptcha:
|
||||
errToReturn = fmt.Errorf("captcha found, please stop sending requests for a while: %w", searchErr)
|
||||
case ErrSearchTimeout:
|
||||
errToReturn = fmt.Errorf("%s", searchErr)
|
||||
default:
|
||||
if errors.Is(searchErr, ErrProxyUnavailable) {
|
||||
errToReturn = fmt.Errorf("%s", searchErr)
|
||||
}
|
||||
}
|
||||
logrus.Errorf("Error during resilient %s %s: %s", engine.Name(), action, searchErr)
|
||||
return fiber.NewError(fiber.StatusServiceUnavailable, errToReturn.Error())
|
||||
}
|
||||
|
||||
cacheStatus := ""
|
||||
// Avoid caching fallback-served responses so the requested engine can recover
|
||||
// without the endpoint continuing to serve another engine until TTL expiry.
|
||||
if s.cache != nil {
|
||||
cacheStatus = "BYPASS"
|
||||
switch {
|
||||
case usedEngine != engine.Name():
|
||||
s.cache.RecordBypass()
|
||||
case len(res) == 0:
|
||||
s.cache.RecordBypass()
|
||||
default:
|
||||
cacheKey := BuildCacheKey(engine.Name(), action, q)
|
||||
if s.cacheJSON(cacheKey, res) {
|
||||
cacheStatus = "MISS"
|
||||
}
|
||||
}
|
||||
c.Set("X-Cache", cacheStatus)
|
||||
}
|
||||
|
||||
if usedEngine != "" && usedEngine != engine.Name() {
|
||||
c.Set("X-Fallback-Engine", usedEngine)
|
||||
}
|
||||
|
||||
logrus.Infof("Successfully completed SERP %s using %s, returned %d results", action, usedEngine, len(res))
|
||||
return c.JSON(res)
|
||||
}
|
||||
|
||||
type HealthStatus struct {
|
||||
Status string `json:"status"`
|
||||
Uptime string `json:"uptime"`
|
||||
Engines []EngineHealth `json:"engines"`
|
||||
System map[string]interface{} `json:"system"`
|
||||
}
|
||||
|
||||
type EngineHealth struct {
|
||||
Name string `json:"name"`
|
||||
Initialized bool `json:"initialized"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// handleHealthCheck returns current service and engine status.
|
||||
// Degraded state stays HTTP 200 to avoid unnecessary restarts in orchestrators.
|
||||
func (s *Server) handleHealthCheck(c *fiber.Ctx) error {
|
||||
engines := make([]EngineHealth, 0, len(s.searchEngines))
|
||||
availableEngines := 0
|
||||
|
||||
for _, engine := range s.searchEngines {
|
||||
status := "ready"
|
||||
isAvailable := true
|
||||
if !engine.IsInitialized() {
|
||||
status = "not_initialized"
|
||||
isAvailable = false
|
||||
}
|
||||
|
||||
for _, cbStat := range s.resilient.GetCircuitBreakerStats() {
|
||||
engineName, _ := cbStat["engine"].(string)
|
||||
if engineName != engine.Name() {
|
||||
continue
|
||||
}
|
||||
circuitState, _ := cbStat["state"].(string)
|
||||
if circuitState == "open" {
|
||||
status = "circuit_open"
|
||||
isAvailable = false
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if isAvailable {
|
||||
availableEngines++
|
||||
}
|
||||
|
||||
engines = append(engines, EngineHealth{
|
||||
Name: engine.Name(),
|
||||
Initialized: engine.IsInitialized(),
|
||||
Status: status,
|
||||
})
|
||||
}
|
||||
|
||||
overallStatus := "healthy"
|
||||
totalEngines := len(s.searchEngines)
|
||||
switch {
|
||||
case totalEngines == 0 || availableEngines == 0:
|
||||
overallStatus = "unhealthy"
|
||||
case availableEngines < totalEngines:
|
||||
overallStatus = "degraded"
|
||||
}
|
||||
|
||||
var memStats runtime.MemStats
|
||||
runtime.ReadMemStats(&memStats)
|
||||
|
||||
health := HealthStatus{
|
||||
Status: overallStatus,
|
||||
Uptime: time.Since(s.startTime).Round(time.Second).String(),
|
||||
Engines: engines,
|
||||
System: map[string]interface{}{
|
||||
"goroutines": runtime.NumGoroutine(),
|
||||
"memory_mb": memStats.Alloc / 1024 / 1024,
|
||||
"go_version": runtime.Version(),
|
||||
},
|
||||
}
|
||||
|
||||
if overallStatus == "unhealthy" {
|
||||
c.Status(fiber.StatusServiceUnavailable)
|
||||
}
|
||||
return c.JSON(health)
|
||||
}
|
||||
|
||||
func (s *Server) handleStats(c *fiber.Ctx) error {
|
||||
return c.JSON(map[string]interface{}{
|
||||
"cache": s.cacheStatsPayload(),
|
||||
"proxy": s.resilient.GetProxyStats(),
|
||||
"circuit_breakers": s.resilient.GetCircuitBreakerStats(),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) handleCacheStats(c *fiber.Ctx) error {
|
||||
return c.JSON(s.cacheStatsPayload())
|
||||
}
|
||||
|
||||
func (s *Server) handleProxyStats(c *fiber.Ctx) error {
|
||||
return c.JSON(s.resilient.GetProxyStats())
|
||||
}
|
||||
|
||||
func (s *Server) handleCircuitBreakerStats(c *fiber.Ctx) error {
|
||||
return c.JSON(map[string]interface{}{
|
||||
"circuit_breakers": s.resilient.GetCircuitBreakerStats(),
|
||||
})
|
||||
}
|
||||
|
||||
type MegaSearchResult struct {
|
||||
SearchResult
|
||||
Engine string `json:"engine"`
|
||||
}
|
||||
|
||||
func (s *Server) handleMegaSearch(c *fiber.Ctx) error {
|
||||
return s.handleMegaEndpoint(c, "search", s.resilient.SearchAllParallel)
|
||||
}
|
||||
|
||||
func (s *Server) handleMegaImage(c *fiber.Ctx) error {
|
||||
return s.handleMegaEndpoint(c, "image", s.resilient.SearchAllImageParallel)
|
||||
}
|
||||
|
||||
func (s *Server) handleMegaEndpoint(c *fiber.Ctx, action string, run func(Query, []SearchEngine) []MegaSearchResult) error {
|
||||
q := Query{}
|
||||
if err := q.InitFromContext(c); err != nil {
|
||||
logrus.Errorf("Error while setting mega %s query: %s", action, err)
|
||||
return err
|
||||
}
|
||||
|
||||
enginesToUse := s.resolveEngines(c.Query("engines", ""))
|
||||
if len(enginesToUse) == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "No valid search engines specified")
|
||||
}
|
||||
|
||||
engineNames := make([]string, len(enginesToUse))
|
||||
for i, engine := range enginesToUse {
|
||||
engineNames[i] = engine.Name()
|
||||
}
|
||||
engineNamesJoined := strings.Join(engineNames, ",")
|
||||
s.applyProxyHeaders(c, s.resilient.ResolveMegaProxyMeta(q, enginesToUse))
|
||||
logrus.Infof("Starting SERP mega %s request using engines: %s for query: %s", action, engineNamesJoined, q.Text)
|
||||
|
||||
cacheHitCandidates := []cacheHitCandidate{
|
||||
{
|
||||
key: s.buildMegaCacheKey(action, enginesToUse, q),
|
||||
logMessage: fmt.Sprintf("Cache hit for mega %s: engines=%s query=%s", action, engineNamesJoined, q.Text),
|
||||
},
|
||||
}
|
||||
cacheableEngines := s.megaCacheableEngines(enginesToUse)
|
||||
if len(cacheableEngines) > 0 && len(cacheableEngines) < len(enginesToUse) {
|
||||
cacheHitCandidates = append(cacheHitCandidates, cacheHitCandidate{
|
||||
key: s.buildMegaCacheKey(action, cacheableEngines, q),
|
||||
logMessage: fmt.Sprintf("Cache hit for mega %s partial set: engines=%s query=%s", action, engineNamesJoined, q.Text),
|
||||
})
|
||||
}
|
||||
if hit, err := s.tryServeCacheHit(c, cacheHitCandidates...); hit || err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
results := run(q, enginesToUse)
|
||||
dedupedResults := s.deduplicateMegaResults(results)
|
||||
|
||||
if s.cache != nil {
|
||||
c.Set("X-Cache", s.cacheMegaResults(action, enginesToUse, q, dedupedResults))
|
||||
}
|
||||
|
||||
logrus.Infof("Successfully completed SERP mega %s using %d engines, returned %d deduplicated results", action, len(enginesToUse), len(dedupedResults))
|
||||
return c.JSON(dedupedResults)
|
||||
}
|
||||
|
||||
func (s *Server) handleListEngines(c *fiber.Ctx) error {
|
||||
var engines []map[string]interface{}
|
||||
|
||||
for _, engine := range s.searchEngines {
|
||||
engineInfo := map[string]interface{}{
|
||||
"name": engine.Name(),
|
||||
"initialized": engine.IsInitialized(),
|
||||
}
|
||||
|
||||
for _, cbStat := range s.resilient.GetCircuitBreakerStats() {
|
||||
engineName, _ := cbStat["engine"].(string)
|
||||
if engineName == engine.Name() {
|
||||
engineInfo["circuit_state"] = cbStat["state"]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
engines = append(engines, engineInfo)
|
||||
}
|
||||
|
||||
return c.JSON(map[string]interface{}{
|
||||
"engines": engines,
|
||||
"total": len(engines),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) resolveEngines(enginesParam string) []SearchEngine {
|
||||
if enginesParam == "" {
|
||||
return s.searchEngines
|
||||
}
|
||||
|
||||
var enginesToUse []SearchEngine
|
||||
seen := make(map[string]bool)
|
||||
engineNames := strings.Split(enginesParam, ",")
|
||||
for _, engineName := range engineNames {
|
||||
engineName = strings.TrimSpace(strings.ToLower(engineName))
|
||||
if engineName == "" || seen[engineName] {
|
||||
continue
|
||||
}
|
||||
for _, engine := range s.searchEngines {
|
||||
if strings.ToLower(engine.Name()) == engineName {
|
||||
enginesToUse = append(enginesToUse, engine)
|
||||
seen[engineName] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return enginesToUse
|
||||
}
|
||||
|
||||
func (s *Server) deduplicateMegaResults(results []MegaSearchResult) []MegaSearchResult {
|
||||
urlMap := make(map[string]MegaSearchResult)
|
||||
|
||||
for _, result := range results {
|
||||
if result.URL == "" {
|
||||
continue
|
||||
}
|
||||
if _, exists := urlMap[result.URL]; !exists {
|
||||
urlMap[result.URL] = result
|
||||
}
|
||||
}
|
||||
|
||||
var deduped []MegaSearchResult
|
||||
for _, result := range urlMap {
|
||||
deduped = append(deduped, result)
|
||||
}
|
||||
|
||||
sort.Slice(deduped, func(i, j int) bool {
|
||||
return deduped[i].Rank < deduped[j].Rank
|
||||
})
|
||||
return deduped
|
||||
}
|
||||
|
||||
type cacheHitCandidate struct {
|
||||
key string
|
||||
logMessage string
|
||||
}
|
||||
|
||||
func (s *Server) tryServeCacheHit(c *fiber.Ctx, candidates ...cacheHitCandidate) (bool, error) {
|
||||
if s.cache == nil {
|
||||
return false, nil
|
||||
}
|
||||
for _, candidate := range candidates {
|
||||
cached, ok := s.cache.Get(candidate.key)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
c.Set("Content-Type", "application/json")
|
||||
c.Set("X-Cache", "HIT")
|
||||
logrus.Info(candidate.logMessage)
|
||||
return true, c.Send(cached)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (s *Server) cacheJSON(cacheKey string, payload interface{}) bool {
|
||||
if s.cache == nil {
|
||||
return false
|
||||
}
|
||||
data, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
s.cache.RecordBypass()
|
||||
return false
|
||||
}
|
||||
s.cache.Set(cacheKey, data)
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *Server) cacheMegaResults(action string, enginesToUse []SearchEngine, q Query, dedupedResults []MegaSearchResult) string {
|
||||
cacheStatus := "BYPASS"
|
||||
if s.cache == nil {
|
||||
return cacheStatus
|
||||
}
|
||||
if len(dedupedResults) == 0 {
|
||||
s.cache.RecordBypass()
|
||||
return cacheStatus
|
||||
}
|
||||
|
||||
cacheEngines := s.megaCacheableEngines(enginesToUse)
|
||||
if len(cacheEngines) == 0 {
|
||||
s.cache.RecordBypass()
|
||||
return cacheStatus
|
||||
}
|
||||
|
||||
if s.cacheJSON(s.buildMegaCacheKey(action, cacheEngines, q), dedupedResults) {
|
||||
return "MISS"
|
||||
}
|
||||
return cacheStatus
|
||||
}
|
||||
|
||||
func (s *Server) buildMegaCacheKey(action string, engines []SearchEngine, q Query) string {
|
||||
names := make([]string, 0, len(engines))
|
||||
for _, eng := range engines {
|
||||
names = append(names, strings.ToLower(strings.TrimSpace(eng.Name())))
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
// Deduplicate engine names in key to keep cache stable when order differs
|
||||
// or repeated names are passed in the engines query parameter.
|
||||
uniq := names[:0]
|
||||
last := ""
|
||||
for _, name := range names {
|
||||
if name == last {
|
||||
continue
|
||||
}
|
||||
uniq = append(uniq, name)
|
||||
last = name
|
||||
}
|
||||
|
||||
return BuildCacheKey("mega:"+strings.Join(uniq, ","), action, q)
|
||||
}
|
||||
|
||||
func (s *Server) megaCacheableEngines(engines []SearchEngine) []SearchEngine {
|
||||
open := make(map[string]bool)
|
||||
for _, stat := range s.resilient.GetCircuitBreakerStats() {
|
||||
name, _ := stat["engine"].(string)
|
||||
state, _ := stat["state"].(string)
|
||||
if strings.EqualFold(state, "open") {
|
||||
open[strings.ToLower(strings.TrimSpace(name))] = true
|
||||
}
|
||||
}
|
||||
|
||||
cacheable := make([]SearchEngine, 0, len(engines))
|
||||
for _, eng := range engines {
|
||||
if open[strings.ToLower(strings.TrimSpace(eng.Name()))] {
|
||||
continue
|
||||
}
|
||||
cacheable = append(cacheable, eng)
|
||||
}
|
||||
return cacheable
|
||||
}
|
||||
|
||||
func (s *Server) cacheStatsPayload() interface{} {
|
||||
if s.cache == nil {
|
||||
return map[string]interface{}{"status": false}
|
||||
}
|
||||
return s.cache.Stats()
|
||||
}
|
||||
|
||||
func (s *Server) applyProxyHeaders(c *fiber.Ctx, meta ProxyExecutionMeta) {
|
||||
mode := meta.Mode
|
||||
if mode == "" {
|
||||
mode = ProxyModeOff
|
||||
}
|
||||
|
||||
tag := meta.Tag
|
||||
used := meta.Used
|
||||
|
||||
if mode == ProxyModeOff {
|
||||
tag = ""
|
||||
used = "direct"
|
||||
}
|
||||
|
||||
c.Set("X-Proxy-Mode", mode)
|
||||
c.Set("X-Proxy-Tag", tag)
|
||||
c.Set("X-Proxy-Used", used)
|
||||
}
|
||||
|
||||
func (s *Server) Listen() error {
|
||||
return s.app.Listen(s.addr)
|
||||
}
|
||||
|
||||
1075
core/server_test.go
1075
core/server_test.go
File diff suppressed because it is too large
Load Diff
@@ -9,10 +9,10 @@ services:
|
||||
- 7000:7000
|
||||
command: serve -l
|
||||
#volumes:
|
||||
# - ./config.yaml:/usr/src/app/config.yaml
|
||||
# - ./config.yaml:/usr/src/app/config.yaml:ro
|
||||
environment:
|
||||
OPENSERP_APP_HOST: "0.0.0.0"
|
||||
OPENSERP_APP_PORT: 7000
|
||||
OPENSERP_SERVER_HOST: "0.0.0.0"
|
||||
OPENSERP_SERVER_PORT: 7000
|
||||
OPENSERP_BAIDU_RATE_REQUESTS: 6 # Number of requests per Minute
|
||||
OPENSERP_BAIDU_RATE_BURST: 2 # Number of non-ratelimited requests per Minute
|
||||
|
||||
|
||||
|
||||
432
duckduckgo/search.go
Normal file
432
duckduckgo/search.go
Normal file
@@ -0,0 +1,432 @@
|
||||
package duckduckgo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/karust/openserp/core"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type DuckDuckGo struct {
|
||||
core.Browser
|
||||
core.SearchEngineOptions
|
||||
pageSleep time.Duration // Sleep between pages
|
||||
logger *core.EngineLogger
|
||||
}
|
||||
|
||||
func New(browser core.Browser, opts core.SearchEngineOptions) *DuckDuckGo {
|
||||
ddg := DuckDuckGo{Browser: browser}
|
||||
opts.Init()
|
||||
ddg.SearchEngineOptions = opts
|
||||
ddg.logger = core.NewEngineLogger("DuckDuckGo")
|
||||
|
||||
ddg.pageSleep = time.Second * 1
|
||||
return &ddg
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) Name() string {
|
||||
return "duckduckgo"
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) GetRateLimiter() *rate.Limiter {
|
||||
ratelimit := rate.Every(ddg.GetRatelimit())
|
||||
return rate.NewLimiter(ratelimit, ddg.RateBurst)
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) isCaptcha(page *rod.Page) bool {
|
||||
html, err := page.Timeout(ddg.GetSelectorTimeout()).HTML()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(html, "bots user")
|
||||
}
|
||||
|
||||
// Check if no results are found
|
||||
func (ddg *DuckDuckGo) isNoResults(page *rod.Page) bool {
|
||||
_, err := page.Timeout(ddg.GetSelectorTimeout()).Search("div[class*='no-results']")
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) parseResults(results rod.Elements, pageNum int) []core.SearchResult {
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
for i, r := range results {
|
||||
// Get URL - try multiple selectors
|
||||
var link *rod.Element
|
||||
var err error
|
||||
|
||||
linkSelectors := []string{
|
||||
"a[data-testid='result-title-a']",
|
||||
"a.result__a",
|
||||
"a.result__url",
|
||||
"h2 a",
|
||||
"h3 a",
|
||||
"a[href]",
|
||||
"a",
|
||||
}
|
||||
|
||||
for _, selector := range linkSelectors {
|
||||
link, err = r.Element(selector)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
ddg.logger.Debug("Missing link")
|
||||
continue
|
||||
}
|
||||
|
||||
linkText, err := link.Property("href")
|
||||
if err != nil {
|
||||
ddg.logger.Debug("Missing href")
|
||||
continue
|
||||
}
|
||||
|
||||
// Validate that we have a proper URL
|
||||
hrefStr := linkText.String()
|
||||
if hrefStr == "" || hrefStr == "#" || hrefStr == "javascript:void(0)" {
|
||||
ddg.logger.Debug("Invalid href: %s", hrefStr)
|
||||
continue
|
||||
}
|
||||
|
||||
// Get title - try multiple selectors
|
||||
var titleTag *rod.Element
|
||||
titleSelectors := []string{
|
||||
"h2",
|
||||
".result__title",
|
||||
".result__a",
|
||||
"span",
|
||||
"div",
|
||||
}
|
||||
|
||||
for _, selector := range titleSelectors {
|
||||
titleTag, err = r.Element(selector)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
title := "No title"
|
||||
if titleTag != nil {
|
||||
title, _ = titleTag.Text()
|
||||
}
|
||||
|
||||
// Get description - try multiple selectors
|
||||
desc := ""
|
||||
descSelectors := []string{
|
||||
"div[data-result='snippet']",
|
||||
".result__snippet",
|
||||
".result__body",
|
||||
"span[class*='snippet']",
|
||||
"div[class*='snippet']",
|
||||
"p",
|
||||
}
|
||||
|
||||
for _, selector := range descSelectors {
|
||||
descTag, err := r.Element(selector)
|
||||
if err == nil {
|
||||
desc = descTag.MustText()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it's an ad
|
||||
isAd := false
|
||||
adSelectors := []string{
|
||||
"[data-testid='ad-badge']",
|
||||
".ad-badge",
|
||||
".result--ad",
|
||||
}
|
||||
|
||||
for _, selector := range adSelectors {
|
||||
adIndicator, err := r.Element(selector)
|
||||
if err == nil && adIndicator != nil {
|
||||
isAd = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
result := core.SearchResult{
|
||||
Rank: (pageNum * 10) + (i + 1),
|
||||
URL: hrefStr,
|
||||
Title: title,
|
||||
Description: desc,
|
||||
Ad: isAd,
|
||||
}
|
||||
searchResults = append(searchResults, result)
|
||||
}
|
||||
|
||||
return searchResults
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
ddg.logger.Debug("Starting search, query: %+v", query)
|
||||
|
||||
allResults := []core.SearchResult{}
|
||||
searchPage := 0
|
||||
|
||||
for len(allResults) < query.Limit {
|
||||
url, err := BuildURL(query, searchPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page, err := ddg.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get all search results in page - try multiple selectors
|
||||
var searchRes *rod.SearchResult
|
||||
var searchErr error
|
||||
|
||||
// Try different selectors for DuckDuckGo results
|
||||
selectors := []string{
|
||||
"article[data-testid='result']",
|
||||
"div[data-testid='result']",
|
||||
"div.result",
|
||||
"div.web-result",
|
||||
".result",
|
||||
"[data-testid='result']",
|
||||
}
|
||||
|
||||
for _, selector := range selectors {
|
||||
searchRes, searchErr = page.Timeout(ddg.GetSelectorTimeout()).Search(selector)
|
||||
if searchErr == nil && searchRes != nil {
|
||||
ddg.logger.Debug("Found results with selector: %s", selector)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if searchErr != nil {
|
||||
defer page.Close()
|
||||
ddg.logger.Error("Cannot parse search results: %s", searchErr)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
// Check why no results, maybe captcha?
|
||||
if searchRes == nil {
|
||||
defer page.Close()
|
||||
|
||||
if ddg.isNoResults(page) {
|
||||
ddg.logger.Warn("No results found")
|
||||
} else if ddg.isCaptcha(page) {
|
||||
ddg.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
elements, err := searchRes.All()
|
||||
if err != nil {
|
||||
ddg.logger.Error("Cannot get search elements: %s", err)
|
||||
break
|
||||
}
|
||||
|
||||
r := ddg.parseResults(elements, searchPage)
|
||||
|
||||
if len(r) == 0 {
|
||||
ddg.logger.Debug("No valid results found on page %d", searchPage)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
allResults = append(allResults, r...)
|
||||
searchPage++
|
||||
|
||||
if !ddg.Browser.LeavePageOpen {
|
||||
// Close tab before opening new one during the cycle
|
||||
err = page.Close()
|
||||
if err != nil {
|
||||
ddg.logger.Debug("Page close error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Break if we've reached or exceeded the limit
|
||||
if len(allResults) >= query.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(ddg.pageSleep)
|
||||
}
|
||||
|
||||
// Deduplicate results
|
||||
deduped := core.DeduplicateResults(allResults)
|
||||
|
||||
// Trim to exact limit if necessary
|
||||
if len(deduped) > query.Limit {
|
||||
deduped = deduped[:query.Limit]
|
||||
}
|
||||
|
||||
ddg.logger.Info("Search completed: %d results", len(deduped))
|
||||
return deduped, nil
|
||||
}
|
||||
|
||||
func (ddg *DuckDuckGo) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
ddg.logger.Debug("Starting image search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
url, err := BuildImageURL(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page, err := ddg.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !ddg.Browser.LeavePageOpen {
|
||||
defer page.Close()
|
||||
}
|
||||
|
||||
// Wait for page to load
|
||||
page.WaitLoad()
|
||||
time.Sleep(time.Second * 2) // Give time for images to load
|
||||
|
||||
// Try multiple selectors for DuckDuckGo image results
|
||||
var searchRes *rod.SearchResult
|
||||
var searchErr error
|
||||
|
||||
selectors := []string{
|
||||
"figure",
|
||||
// "figure.nsogf_Hpj9UUxfhcwQd5",
|
||||
// "div[data-testid='result']",
|
||||
// "div.tile--img",
|
||||
// "div.tile.tile--img",
|
||||
// "div.js-images-show-more",
|
||||
// "div.img-result",
|
||||
}
|
||||
|
||||
ddg.logger.Debug("Trying selectors: %v", selectors)
|
||||
|
||||
for _, selector := range selectors {
|
||||
searchRes, searchErr = page.Timeout(ddg.GetSelectorTimeout()).Search(selector)
|
||||
if searchErr == nil && searchRes != nil {
|
||||
ddg.logger.Debug("Found image results with selector: %s", selector)
|
||||
break
|
||||
} else {
|
||||
ddg.logger.Debug("Selector '%s' not found: %v", selector, searchErr)
|
||||
}
|
||||
}
|
||||
|
||||
if searchErr != nil {
|
||||
ddg.logger.Error("Cannot find image results: %s", searchErr)
|
||||
return searchResults, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
// Check why no results
|
||||
if searchRes == nil {
|
||||
if ddg.isCaptcha(page) {
|
||||
ddg.logger.Error("Captcha detected: %s", url)
|
||||
return searchResults, core.ErrCaptcha
|
||||
} else if ddg.isNoResults(page) {
|
||||
ddg.logger.Warn("No image results found")
|
||||
}
|
||||
return searchResults, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
elements, err := searchRes.All()
|
||||
if err != nil {
|
||||
ddg.logger.Error("Cannot get search elements: %s", err)
|
||||
return searchResults, err
|
||||
}
|
||||
|
||||
ddg.logger.Info("Found %d image elements", len(elements))
|
||||
|
||||
for i, r := range elements {
|
||||
// Get image URL - try multiple selectors
|
||||
var imgTag *rod.Element
|
||||
var imgErr error
|
||||
|
||||
imgSelectors := []string{
|
||||
"img",
|
||||
"div.SZ76bwIlqO8BBoqOLqYV img",
|
||||
"img[src*='duckduckgo.com']",
|
||||
}
|
||||
|
||||
for _, selector := range imgSelectors {
|
||||
imgTag, imgErr = r.Element(selector)
|
||||
if imgErr == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if imgErr != nil {
|
||||
ddg.logger.Debug("Missing img tag for element %d", i)
|
||||
continue
|
||||
}
|
||||
|
||||
imgSrc, err := imgTag.Property("src")
|
||||
if err != nil {
|
||||
ddg.logger.Debug("Missing src property for image %d", i)
|
||||
continue
|
||||
}
|
||||
|
||||
// Get title - try multiple selectors based on the HTML structure
|
||||
var titleTag *rod.Element
|
||||
var titleErr error
|
||||
|
||||
titleSelectors := []string{
|
||||
"figcaption a p span",
|
||||
"figcaption span",
|
||||
"figcaption p span",
|
||||
"span.EKtkFWMYpwzMKOYr0GYm",
|
||||
"h3",
|
||||
"span",
|
||||
"p",
|
||||
}
|
||||
|
||||
for _, selector := range titleSelectors {
|
||||
titleTag, titleErr = r.Element(selector)
|
||||
if titleErr == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
title := "No title"
|
||||
if titleTag != nil {
|
||||
title, _ = titleTag.Text()
|
||||
}
|
||||
|
||||
// Get source page URL - try multiple selectors
|
||||
var linkTag *rod.Element
|
||||
var linkErr error
|
||||
|
||||
linkSelectors := []string{
|
||||
"figcaption a",
|
||||
"a",
|
||||
}
|
||||
|
||||
for _, selector := range linkSelectors {
|
||||
linkTag, linkErr = r.Element(selector)
|
||||
if linkErr == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
sourceURL := ""
|
||||
if linkTag != nil {
|
||||
href, err := linkTag.Property("href")
|
||||
if err == nil {
|
||||
sourceURL = href.String()
|
||||
}
|
||||
}
|
||||
|
||||
result := core.SearchResult{
|
||||
Rank: i + 1,
|
||||
URL: imgSrc.String(),
|
||||
Title: title,
|
||||
Description: fmt.Sprintf("Source: %s", sourceURL),
|
||||
}
|
||||
|
||||
searchResults = append(searchResults, result)
|
||||
}
|
||||
|
||||
ddg.logger.Info("Parsed %d image results", len(searchResults))
|
||||
return core.DeduplicateResults(searchResults), nil
|
||||
}
|
||||
103
duckduckgo/search_test.go
Normal file
103
duckduckgo/search_test.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package duckduckgo
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
func TestBuildURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
query core.Query
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Basic search",
|
||||
query: core.Query{
|
||||
Text: "golang programming",
|
||||
},
|
||||
expected: "https://duckduckgo.com/?q=golang+programming&t=h&ia=web",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Search with site filter",
|
||||
query: core.Query{
|
||||
Text: "golang",
|
||||
Site: "github.com",
|
||||
},
|
||||
expected: "https://duckduckgo.com/?q=golang+site%3Agithub.com&t=h&ia=web",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Search with filetype",
|
||||
query: core.Query{
|
||||
Text: "documentation",
|
||||
Filetype: "pdf",
|
||||
},
|
||||
expected: "https://duckduckgo.com/?q=documentation+filetype%3Apdf&t=h&ia=web",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Empty query",
|
||||
query: core.Query{
|
||||
Text: "",
|
||||
},
|
||||
expected: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := BuildURL(tt.query)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("BuildURL() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.expected {
|
||||
t.Errorf("BuildURL() = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildImageURL(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
query core.Query
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Basic image search",
|
||||
query: core.Query{
|
||||
Text: "golang logo",
|
||||
},
|
||||
expected: "https://duckduckgo.com/?q=golang+logo&t=h&iax=images&ia=images",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Empty query",
|
||||
query: core.Query{
|
||||
Text: "",
|
||||
},
|
||||
expected: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := BuildImageURL(tt.query)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("BuildImageURL() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.expected {
|
||||
t.Errorf("BuildImageURL() = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
148
duckduckgo/url.go
Normal file
148
duckduckgo/url.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package duckduckgo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
const baseURL = "https://duckduckgo.com"
|
||||
|
||||
func BuildURL(q core.Query, page int) (string, error) {
|
||||
base, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
base.Path += ""
|
||||
params := url.Values{}
|
||||
|
||||
// Set request text
|
||||
if q.Text != "" || q.Site != "" || q.Filetype != "" {
|
||||
text := q.Text
|
||||
if q.Site != "" {
|
||||
text += " site:" + q.Site
|
||||
}
|
||||
if q.Filetype != "" {
|
||||
text += " filetype:" + q.Filetype
|
||||
}
|
||||
|
||||
params.Add("q", text)
|
||||
}
|
||||
|
||||
if len(params.Get("q")) == 0 {
|
||||
return "", errors.New("empty query built")
|
||||
}
|
||||
|
||||
// Set search date range
|
||||
if q.DateInterval != "" {
|
||||
intervals := strings.Split(q.DateInterval, "..")
|
||||
if len(intervals) != 2 {
|
||||
return "", errors.New("incorrect date interval provided")
|
||||
}
|
||||
|
||||
// Convert from YYYYMMDD to YYYY-MM-DD format (DuckDuckGo requirement)
|
||||
startDate, err := time.Parse("20060102", intervals[0])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid start date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
endDate, err := time.Parse("20060102", intervals[1])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid end date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
// DuckDuckGo uses YYYY-MM-DD..YYYY-MM-DD format
|
||||
dateRange := fmt.Sprintf("%s..%s",
|
||||
startDate.Format("2006-01-02"),
|
||||
endDate.Format("2006-01-02"))
|
||||
params.Add("df", dateRange)
|
||||
}
|
||||
|
||||
// Set language
|
||||
if q.LangCode != "" {
|
||||
params.Add("kl", strings.ToLower(q.LangCode))
|
||||
}
|
||||
|
||||
// DuckDuckGo specific parameters
|
||||
params.Add("t", "h") // HTML format
|
||||
params.Add("ia", "web") // Web search
|
||||
|
||||
// Add pagination parameter if not on first page
|
||||
if page > 0 {
|
||||
// DuckDuckGo uses 's' parameter for pagination (start offset)
|
||||
// Each page has approximately 25-30 results, but we'll use conservative estimate
|
||||
offset := page * 25
|
||||
params.Add("s", fmt.Sprintf("%d", offset))
|
||||
}
|
||||
|
||||
base.RawQuery = params.Encode()
|
||||
return base.String(), nil
|
||||
}
|
||||
|
||||
func BuildImageURL(q core.Query) (string, error) {
|
||||
base, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
base.Path += ""
|
||||
params := url.Values{}
|
||||
params.Add("t", "h") // HTML format
|
||||
params.Add("iax", "images") // Image search
|
||||
params.Add("ia", "images")
|
||||
|
||||
// Set request text
|
||||
if q.Text != "" || q.Site != "" || q.Filetype != "" {
|
||||
text := q.Text
|
||||
if q.Site != "" {
|
||||
text += " site:" + q.Site
|
||||
}
|
||||
if q.Filetype != "" {
|
||||
text += " filetype:" + q.Filetype
|
||||
}
|
||||
|
||||
params.Add("q", text)
|
||||
}
|
||||
|
||||
if len(params.Get("q")) == 0 {
|
||||
return "", errors.New("empty query built")
|
||||
}
|
||||
|
||||
// Set search date range
|
||||
if q.DateInterval != "" {
|
||||
intervals := strings.Split(q.DateInterval, "..")
|
||||
if len(intervals) != 2 {
|
||||
return "", errors.New("incorrect date interval provided")
|
||||
}
|
||||
|
||||
// Convert from YYYYMMDD to YYYY-MM-DD format (DuckDuckGo requirement)
|
||||
startDate, err := time.Parse("20060102", intervals[0])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid start date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
endDate, err := time.Parse("20060102", intervals[1])
|
||||
if err != nil {
|
||||
return "", errors.New("invalid end date format, expected YYYYMMDD")
|
||||
}
|
||||
|
||||
// DuckDuckGo uses YYYY-MM-DD..YYYY-MM-DD format
|
||||
dateRange := fmt.Sprintf("%s..%s",
|
||||
startDate.Format("2006-01-02"),
|
||||
endDate.Format("2006-01-02"))
|
||||
params.Add("df", dateRange)
|
||||
}
|
||||
|
||||
// Set language
|
||||
if q.LangCode != "" {
|
||||
params.Add("kl", strings.ToLower(q.LangCode))
|
||||
}
|
||||
|
||||
base.RawQuery = params.Encode()
|
||||
return base.String(), nil
|
||||
}
|
||||
76
go.mod
76
go.mod
@@ -1,57 +1,55 @@
|
||||
module github.com/karust/openserp
|
||||
|
||||
go 1.20
|
||||
go 1.24
|
||||
|
||||
toolchain go1.24.6
|
||||
|
||||
require (
|
||||
github.com/2captcha/2captcha-go v1.1.4
|
||||
github.com/PuerkitoBio/goquery v1.8.1
|
||||
github.com/2captcha/2captcha-go v1.1.10
|
||||
github.com/PuerkitoBio/goquery v1.10.3
|
||||
github.com/corpix/uarand v0.2.0
|
||||
github.com/go-rod/rod v0.113.3
|
||||
github.com/go-rod/rod v0.116.2
|
||||
github.com/go-rod/stealth v0.4.9
|
||||
github.com/gofiber/fiber/v2 v2.47.0
|
||||
github.com/gofiber/fiber/v2 v2.52.9
|
||||
github.com/refraction-networking/utls v1.8.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cobra v1.7.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.16.0
|
||||
golang.org/x/time v0.3.0
|
||||
github.com/spf13/cobra v1.9.1
|
||||
github.com/spf13/pflag v1.0.7
|
||||
github.com/spf13/viper v1.20.1
|
||||
golang.org/x/time v0.12.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/andybalholm/brotli v1.2.0 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.3 // indirect
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/klauspost/compress v1.16.6 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||
github.com/philhofer/fwd v1.1.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/rogpeppe/go-internal v1.10.0 // indirect
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
|
||||
github.com/spf13/afero v1.9.5 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/subosito/gotenv v1.4.2 // indirect
|
||||
github.com/tinylib/msgp v1.1.8 // indirect
|
||||
github.com/sagikazarmark/locafero v0.10.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/spf13/afero v1.14.0 // indirect
|
||||
github.com/spf13/cast v1.9.2 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.48.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
github.com/ysmood/fetchup v0.2.3 // indirect
|
||||
github.com/valyala/fasthttp v1.65.0 // indirect
|
||||
github.com/ysmood/fetchup v0.3.0 // indirect
|
||||
github.com/ysmood/goob v0.4.0 // indirect
|
||||
github.com/ysmood/got v0.34.1 // indirect
|
||||
github.com/ysmood/got v0.41.0 // indirect
|
||||
github.com/ysmood/gson v0.7.3 // indirect
|
||||
github.com/ysmood/leakless v0.8.0 // indirect
|
||||
golang.org/x/net v0.11.0 // indirect
|
||||
golang.org/x/sys v0.9.0 // indirect
|
||||
golang.org/x/text v0.10.0 // indirect
|
||||
github.com/ysmood/leakless v0.9.0 // indirect
|
||||
golang.org/x/crypto v0.41.0 // indirect
|
||||
golang.org/x/net v0.43.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
630
go.sum
630
go.sum
@@ -1,591 +1,191 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||
cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
||||
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
||||
cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
|
||||
cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
|
||||
cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
|
||||
cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
|
||||
cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk=
|
||||
cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
|
||||
cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
|
||||
cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
|
||||
cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI=
|
||||
cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk=
|
||||
cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
|
||||
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
|
||||
cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
|
||||
cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
|
||||
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
|
||||
cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
|
||||
cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
|
||||
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
|
||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
||||
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/2captcha/2captcha-go v1.1.4 h1:Fm62VPvVhEHYQ8AI+/uquiTg41ml9f8ASjUkVuBvHcE=
|
||||
github.com/2captcha/2captcha-go v1.1.4/go.mod h1:hYOq+KVOq/0zAG6OTYW7Y313qDkHv58CcaOyjdBQSco=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/PuerkitoBio/goquery v1.8.1 h1:uQxhNlArOIdbrH1tr0UXwdVFgDcZDrZVdcpygAcwmWM=
|
||||
github.com/PuerkitoBio/goquery v1.8.1/go.mod h1:Q8ICL1kNUJ2sXGoAhPGUdYDJvgQgHzJsnnd3H7Ho5jQ=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
|
||||
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/2captcha/2captcha-go v1.1.10 h1:U3Y7VLwR9z5XpCMijB+FkhHRt6QikKnHDEy1uLQVCD8=
|
||||
github.com/2captcha/2captcha-go v1.1.10/go.mod h1:TsupeToBP0BPHfZOQpNDb61NKqtbBJ2ddptqSK2p9/M=
|
||||
github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
|
||||
github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
|
||||
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
|
||||
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
|
||||
github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/corpix/uarand v0.2.0 h1:U98xXwud/AVuCpkpgfPF7J5TQgr7R5tqT8VZP5KWbzE=
|
||||
github.com/corpix/uarand v0.2.0/go.mod h1:/3Z1QIqWkDIhf6XWn/08/uMHoQ8JUoTIKc2iPchBOmM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-rod/rod v0.113.0/go.mod h1:aiedSEFg5DwG/fnNbUOTPMTTWX3MRj6vIs/a684Mthw=
|
||||
github.com/go-rod/rod v0.113.3 h1:oLiKZW721CCMwA5g7977cWfcAKQ+FuosP47Zf1QiDrA=
|
||||
github.com/go-rod/rod v0.113.3/go.mod h1:aiedSEFg5DwG/fnNbUOTPMTTWX3MRj6vIs/a684Mthw=
|
||||
github.com/go-rod/rod v0.116.2 h1:A5t2Ky2A+5eD/ZJQr1EfsQSe5rms5Xof/qj296e+ZqA=
|
||||
github.com/go-rod/rod v0.116.2/go.mod h1:H+CMO9SCNc2TJ2WfrG+pKhITz57uGNYU43qYHh438Mg=
|
||||
github.com/go-rod/stealth v0.4.9 h1:X2PmQk4DUF2wzw6GOsWjW/glb8K5ebnftbEvLh7MlZ4=
|
||||
github.com/go-rod/stealth v0.4.9/go.mod h1:eAzyvw8c0iAd5nJJsSWeh0fQ5z94vCIfdi1hUmYDimc=
|
||||
github.com/gofiber/fiber/v2 v2.47.0 h1:EN5lHVCc+Pyqh5OEsk8fzRiifgwpbrP0rulQ4iNf3fs=
|
||||
github.com/gofiber/fiber/v2 v2.47.0/go.mod h1:mbFMVN1lQuzziTkkakgtKKdjfsXSw9BKR5lmcNksUoU=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||
github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
|
||||
github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
|
||||
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
||||
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
||||
github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU=
|
||||
github.com/philhofer/fwd v1.1.2 h1:bnDivRJ1EWPjUIRXV5KfORO897HTbpFAQddBdE8t7Gw=
|
||||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/refraction-networking/utls v1.8.0 h1:L38krhiTAyj9EeiQQa2sg+hYb4qwLCqdMcpZrRfbONE=
|
||||
github.com/refraction-networking/utls v1.8.0/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94 h1:rmMl4fXJhKMNWl+K+r/fq4FbbKI+Ia2m9hYBLm2h4G4=
|
||||
github.com/savsgio/dictpool v0.0.0-20221023140959-7bf2e61cea94/go.mod h1:90zrgN3D/WJsDd1iXHT96alCoN2KJo6/4x1DZC3wZs8=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee h1:8Iv5m6xEo1NR1AvpV+7XmhI4r39LGNzwUL4YpMuL5vk=
|
||||
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee/go.mod h1:qwtSXrKuJh/zsFQ12yEE89xfCrGKK63Rr7ctU/uCo4g=
|
||||
github.com/sagikazarmark/locafero v0.10.0 h1:FM8Cv6j2KqIhM2ZK7HZjm4mpj9NBktLgowT1aN9q5Cc=
|
||||
github.com/sagikazarmark/locafero v0.10.0/go.mod h1:Ieo3EUsjifvQu4NZwV5sPd4dwvu0OCgEQV7vjc9yDjw=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
|
||||
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
|
||||
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
|
||||
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
||||
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc=
|
||||
github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw=
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U=
|
||||
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=
|
||||
github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo=
|
||||
github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE=
|
||||
github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
|
||||
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
|
||||
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
|
||||
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
|
||||
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
|
||||
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
|
||||
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
|
||||
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
|
||||
github.com/tinylib/msgp v1.1.8 h1:FCXC1xanKO4I8plpHGH2P7koL/RzZs12l/+r7vakfm0=
|
||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
|
||||
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/ysmood/fetchup v0.2.3 h1:ulX+SonA0Vma5zUFXtv52Kzip/xe7aj4vqT5AJwQ+ZQ=
|
||||
github.com/valyala/fasthttp v1.65.0 h1:j/u3uzFEGFfRxw79iYzJN+TteTJwbYkru9uDp3d0Yf8=
|
||||
github.com/valyala/fasthttp v1.65.0/go.mod h1:P/93/YkKPMsKSnATEeELUCkG8a7Y+k99uxNHVbKINr4=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
github.com/ysmood/fetchup v0.2.3/go.mod h1:xhibcRKziSvol0H1/pj33dnKrYyI2ebIvz5cOOkYGns=
|
||||
github.com/ysmood/fetchup v0.3.0 h1:UhYz9xnLEVn2ukSuK3KCgcznWpHMdrmbsPpllcylyu8=
|
||||
github.com/ysmood/fetchup v0.3.0/go.mod h1:hbysoq65PXL0NQeNzUczNYIKpwpkwFL4LXMDEvIQq9A=
|
||||
github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
|
||||
github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
|
||||
github.com/ysmood/gop v0.0.2 h1:VuWweTmXK+zedLqYufJdh3PlxDNBOfFHjIZlPT2T5nw=
|
||||
github.com/ysmood/gop v0.0.2/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk=
|
||||
github.com/ysmood/got v0.34.1 h1:IrV2uWLs45VXNvZqhJ6g2nIhY+pgIG1CUoOcqfXFl1s=
|
||||
github.com/ysmood/gop v0.2.0 h1:+tFrG0TWPxT6p9ZaZs+VY+opCvHU8/3Fk6BaNv6kqKg=
|
||||
github.com/ysmood/gop v0.2.0/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk=
|
||||
github.com/ysmood/got v0.34.1/go.mod h1:yddyjq/PmAf08RMLSwDjPyCvHvYed+WjHnQxpH851LM=
|
||||
github.com/ysmood/got v0.41.0 h1:XiFH311ltTSGyxjeKcNvy7dzbJjjTzn6DBgK313JHBs=
|
||||
github.com/ysmood/got v0.41.0/go.mod h1:W7DdpuX6skL3NszLmAsC5hT7JAhuLZhByVzHTq874Qg=
|
||||
github.com/ysmood/gotrace v0.6.0 h1:SyI1d4jclswLhg7SWTL6os3L1WOKeNn/ZtzVQF8QmdY=
|
||||
github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
|
||||
github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE=
|
||||
github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg=
|
||||
github.com/ysmood/leakless v0.8.0 h1:BzLrVoiwxikpgEQR0Lk8NyBN5Cit2b1z+u0mgL4ZJak=
|
||||
github.com/ysmood/leakless v0.8.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/ysmood/leakless v0.9.0 h1:qxCG5VirSBvmi3uynXFkcnLMzkphdh3xx5FtrORwDCU=
|
||||
github.com/ysmood/leakless v0.9.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
|
||||
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
||||
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
|
||||
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
||||
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
|
||||
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
||||
google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
||||
google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
||||
google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
|
||||
google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
|
||||
google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
|
||||
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
|
||||
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
|
||||
google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
|
||||
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
|
||||
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
||||
|
||||
167
google/search.go
167
google/search.go
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/go-rod/rod/lib/proto"
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
@@ -19,13 +18,15 @@ type Google struct {
|
||||
core.Browser
|
||||
core.SearchEngineOptions
|
||||
rgxpGetDigits *regexp.Regexp
|
||||
logger *core.EngineLogger
|
||||
}
|
||||
|
||||
func New(browser core.Browser, opts core.SearchEngineOptions) *Google {
|
||||
gogl := Google{Browser: browser}
|
||||
opts.Init()
|
||||
gogl.SearchEngineOptions = opts
|
||||
gogl.rgxpGetDigits = regexp.MustCompile("\\d")
|
||||
gogl.logger = core.NewEngineLogger("Google")
|
||||
gogl.rgxpGetDigits = regexp.MustCompile(`\d`)
|
||||
return &gogl
|
||||
}
|
||||
|
||||
@@ -68,18 +69,18 @@ func (gogl *Google) getTotalResults(page *rod.Page) (int, error) {
|
||||
}
|
||||
|
||||
func (gogl *Google) solveCaptcha(page *rod.Page, sitekey, datas string) bool {
|
||||
logrus.Debugf("Solve google Captcha: sitekey=%s, datas=%s, url=%s", sitekey, datas, page.MustInfo().URL)
|
||||
gogl.logger.Debug("Solve captcha: sitekey=%s", sitekey)
|
||||
|
||||
resp, err := gogl.CaptchaSolver.SolveReCaptcha2(sitekey, page.MustInfo().URL, datas)
|
||||
resp, _, err := gogl.CaptchaSolver.SolveReCaptcha2(sitekey, page.MustInfo().URL, datas)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error solving google captcha: %s", err)
|
||||
gogl.logger.Error("Captcha solve failed: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
logrus.Debug("Resp:", resp)
|
||||
gogl.logger.Debug("Captcha response received")
|
||||
_, err = page.Eval(fmt.Sprintf(`;(() => { document.getElementById("g-recaptcha-response").innerHTML="%s"; submitCallback(); })();`, resp))
|
||||
if err != nil {
|
||||
logrus.Errorf("Error setting captcha response: %s", err)
|
||||
gogl.logger.Error("Failed to set captcha response: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -94,13 +95,13 @@ func (gogl *Google) checkCaptcha(page *rod.Page) bool {
|
||||
|
||||
sitekey, err := captchaDiv.First.Attribute("data-sitekey")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot get Google captcha sitekey: %s", err)
|
||||
gogl.logger.Error("Cannot get captcha sitekey: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
dataS, err := captchaDiv.First.Attribute("data-s")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot get Google captcha datas: %s", err)
|
||||
gogl.logger.Error("Cannot get captcha datas: %s", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -112,28 +113,31 @@ func (gogl *Google) checkCaptcha(page *rod.Page) bool {
|
||||
|
||||
func (gogl *Google) preparePage(page *rod.Page) {
|
||||
// Remove "similar queries" lists
|
||||
_, err := page.Eval(";(() => { document.querySelectorAll(`div[data-initq]`).forEach( el => el.remove()); })();")
|
||||
_, err := page.Eval(`() => {
|
||||
document.querySelectorAll("div[data-initq]").forEach((el) => el.remove())
|
||||
}`)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error preparing the page: %s", err)
|
||||
gogl.logger.Debug("Page preparation skipped: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (gogl *Google) acceptCookies(page *rod.Page) {
|
||||
diaglogBtns, err := page.Timeout(gogl.Timeout / 10).Search("div[role='dialog'][aria-modal] button")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot find cookie consent: %s", err)
|
||||
gogl.logger.Debug("Cookie consent not found: %s", err)
|
||||
return
|
||||
}
|
||||
btnElms, err := diaglogBtns.All()
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot get cookie consent buttons: %s", err)
|
||||
gogl.logger.Debug("Cannot get cookie consent buttons: %s", err)
|
||||
return
|
||||
}
|
||||
btnElms[3].Click(proto.InputMouseButtonLeft, 1)
|
||||
|
||||
}
|
||||
|
||||
func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Google search, query: %+v", query)
|
||||
gogl.logger.Debug("Starting search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
@@ -142,13 +146,17 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
page := gogl.Navigate(url)
|
||||
page, err := gogl.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer gogl.close(page)
|
||||
gogl.preparePage(page)
|
||||
|
||||
// Check first if there captcha
|
||||
if gogl.checkCaptcha(page) {
|
||||
logrus.Errorf("Google captcha occurred during: %s", url)
|
||||
gogl.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
|
||||
@@ -157,10 +165,10 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
gogl.acceptCookies(page)
|
||||
}
|
||||
|
||||
// Find all results
|
||||
results, err := page.Timeout(gogl.Timeout).Search("div[data-hveid]")
|
||||
// Find all results using stable attributes
|
||||
results, err := page.Timeout(gogl.Timeout).Search("div[data-hveid][data-ved]")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot parse search results: %s", err)
|
||||
gogl.logger.Error("Cannot parse search results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
@@ -170,16 +178,16 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
totalResults, err := gogl.getTotalResults(page)
|
||||
if err != nil {
|
||||
logrus.Errorf("Error capturing total results: %v", err)
|
||||
gogl.logger.Debug("Failed to get total results: %v", err)
|
||||
}
|
||||
logrus.Infof("%d SERP results", totalResults)
|
||||
gogl.logger.Info("Found %d total results", totalResults)
|
||||
|
||||
searchResultElems, err := results.All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rank := 0
|
||||
rank := query.Start
|
||||
for _, resEl := range searchResultElems {
|
||||
srchRes := core.SearchResult{}
|
||||
|
||||
@@ -193,14 +201,14 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
// Get URL
|
||||
link, err := resEl.Element("a")
|
||||
if err != nil {
|
||||
logrus.Debug("No link found")
|
||||
gogl.logger.Debug("Missing link")
|
||||
continue
|
||||
}
|
||||
link.MoveMouseOut()
|
||||
|
||||
href, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Debug("No `href` tag found")
|
||||
gogl.logger.Debug("Missing href")
|
||||
continue
|
||||
}
|
||||
srchRes.URL = href.String()
|
||||
@@ -218,17 +226,17 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
// 2. Parse answer boxes
|
||||
answerEls, err := resEl.Page().Search("div[data-hveid][data-ulkwtsb] div[data-q]")
|
||||
if err != nil {
|
||||
logrus.Debugf("Error while parsing answer box 1: %s", err.Error())
|
||||
gogl.logger.Debug("Answer parsing failed: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
answers, err := answerEls.All()
|
||||
if err != nil {
|
||||
logrus.Debugf("Error while parsing answer box 2: %s", err.Error())
|
||||
gogl.logger.Debug("Answer parsing failed: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
logrus.Infof("%d answers found", len(answers))
|
||||
gogl.logger.Info("Found %d answers", len(answers))
|
||||
|
||||
// Unvail answer contents
|
||||
for _, answ := range answers {
|
||||
@@ -241,21 +249,21 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
for i, answ := range answers {
|
||||
answerText := strings.Split(answ.MustText(), "\n")
|
||||
if len(answerText) < 2 {
|
||||
logrus.Debugf("Short answer text: %s", answerText)
|
||||
gogl.logger.Debug("Short answer text: %s", answerText)
|
||||
continue
|
||||
}
|
||||
|
||||
// Get URL
|
||||
link, err := answ.Element("a")
|
||||
if err != nil {
|
||||
logrus.Debug("No answer link found")
|
||||
gogl.logger.Debug("Missing answer link")
|
||||
continue
|
||||
}
|
||||
link.MoveMouseOut()
|
||||
|
||||
href, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Debug("No answer `href` tag found")
|
||||
gogl.logger.Debug("Missing answer href")
|
||||
continue
|
||||
}
|
||||
srchRes.URL = href.String()
|
||||
@@ -265,35 +273,56 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
searchResults = append(searchResults, srchRes)
|
||||
}
|
||||
continue
|
||||
} else if strings.Contains(attrs, "data-ved") && strings.Contains(attrs, "lang") {
|
||||
// 3. Parse regular search results
|
||||
// Get URL
|
||||
link, err := resEl.Element("a")
|
||||
} else if strings.Contains(attrs, "data-ved") {
|
||||
// Parse regular search results
|
||||
// Get title from h3
|
||||
titleTag, err := resEl.Element("h3")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
href, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Debug("No `href` tag found")
|
||||
srchRes.Title, _ = titleTag.Text()
|
||||
|
||||
// Get URL from parent link of h3
|
||||
link, err := titleTag.Parent()
|
||||
if err == nil && link.MustMatches("a") {
|
||||
href, _ := link.Property("href")
|
||||
srchRes.URL = href.String()
|
||||
}
|
||||
srchRes.URL = href.String()
|
||||
|
||||
// Skip if URL is empty
|
||||
if srchRes.URL == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get description using multiple fallback strategies
|
||||
desc := ""
|
||||
if descTag, err := resEl.Element("div[data-sncf='1'] div"); err == nil {
|
||||
desc = descTag.MustText()
|
||||
} else if descTag, err := resEl.Element("div.VwiC3b"); err == nil {
|
||||
desc = descTag.MustText()
|
||||
} else {
|
||||
// Structural fallback
|
||||
parent, err := titleTag.Parent()
|
||||
if err == nil {
|
||||
parent, err = parent.Parent()
|
||||
if err == nil {
|
||||
parent, err = parent.Parent()
|
||||
if err == nil {
|
||||
if descTag, err := parent.Next(); err == nil {
|
||||
if descDiv, err := descTag.Element("div"); err == nil {
|
||||
desc = descDiv.MustText()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
srchRes.Description = desc
|
||||
|
||||
rank += 1
|
||||
|
||||
// Get title
|
||||
titleTag, err := link.Element("h3")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
srchRes.Title, err = titleTag.Text()
|
||||
if err != nil {
|
||||
logrus.Debug("Cannot extract text from title")
|
||||
}
|
||||
|
||||
// Get description
|
||||
text := resEl.MustText()
|
||||
textSliced := strings.Split(text, "\n")
|
||||
srchRes.Description = strings.Join(textSliced[:], "\n")
|
||||
srchRes.Rank = rank
|
||||
searchResults = append(searchResults, srchRes)
|
||||
continue
|
||||
|
||||
} else {
|
||||
//fmt.Println(i, attrs)
|
||||
@@ -304,11 +333,11 @@ func (gogl *Google) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
searchResults = append(searchResults, srchRes)
|
||||
}
|
||||
|
||||
return searchResults, nil
|
||||
return core.DeduplicateResults(searchResults), nil
|
||||
}
|
||||
|
||||
func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Google Image search, query: %+v", query)
|
||||
gogl.logger.Debug("Starting image search, query: %+v", query)
|
||||
|
||||
searchResultsMap := map[string]core.SearchResult{}
|
||||
url, err := BuildImageURL(query)
|
||||
@@ -316,7 +345,11 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page := gogl.Navigate(url)
|
||||
page, err := gogl.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer gogl.close(page)
|
||||
|
||||
for len(searchResultsMap) < query.Limit {
|
||||
@@ -324,16 +357,16 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
page.Mouse.Scroll(0, 1000000, 1)
|
||||
page.WaitLoad()
|
||||
|
||||
results, err := page.Timeout(gogl.Timeout).Search("div[data-hveid][data-ved][jsaction][jsdata]")
|
||||
results, err := page.Timeout(gogl.Timeout).Search("div[data-hveid][data-ved][jsaction]")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot parse search results: %s", err)
|
||||
gogl.logger.Error("Cannot parse search results: %s", err)
|
||||
return *core.ConvertSearchResultsMap(searchResultsMap), core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
// Check why no results
|
||||
if results == nil {
|
||||
if gogl.checkCaptcha(page) {
|
||||
logrus.Errorf("Google captcha occurred during: %s", url)
|
||||
gogl.logger.Error("Captcha detected: %s", url)
|
||||
return *core.ConvertSearchResultsMap(searchResultsMap), core.ErrCaptcha
|
||||
}
|
||||
return *core.ConvertSearchResultsMap(searchResultsMap), err
|
||||
@@ -352,13 +385,13 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
// TODO: parse AF_initDataCallback to optimize instead of this?
|
||||
err := r.Click(proto.InputMouseButtonRight, 1)
|
||||
if err != nil {
|
||||
logrus.Error("Error clicking")
|
||||
gogl.logger.Error("Click failed")
|
||||
continue
|
||||
}
|
||||
|
||||
dataVed, err := r.Attribute("data-ved")
|
||||
if err != nil {
|
||||
logrus.Error("Cannot find `data-ved` attr")
|
||||
gogl.logger.Error("Missing data-ved attribute")
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -375,25 +408,25 @@ func (gogl *Google) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
linkText, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Error("No `href` tag found")
|
||||
gogl.logger.Error("Missing href")
|
||||
}
|
||||
|
||||
imgSrc, err := parseSourceImageURL(linkText.String())
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot parse image href: %v", err)
|
||||
gogl.logger.Error("Failed to parse image URL: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Get title
|
||||
titleTag, err := r.Element("h3")
|
||||
if err != nil {
|
||||
logrus.Error("No `h3` tag found")
|
||||
gogl.logger.Error("Missing h3 tag")
|
||||
continue
|
||||
}
|
||||
|
||||
title, err := titleTag.Text()
|
||||
if err != nil {
|
||||
logrus.Error("Cannot extract text from title")
|
||||
gogl.logger.Error("Failed to extract title")
|
||||
title = "No title"
|
||||
}
|
||||
|
||||
@@ -416,7 +449,7 @@ func (gogl *Google) close(page *rod.Page) {
|
||||
if !gogl.Browser.LeavePageOpen {
|
||||
err := page.Close()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
gogl.logger.Debug("Page close error: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func googleRequest(searchURL string) (*http.Response, error) {
|
||||
baseClient := &http.Client{}
|
||||
func googleRequest(searchURL string, query core.Query) (*http.Response, error) {
|
||||
baseClient, err := core.NewRawHTTPClient(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", searchURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -26,7 +30,7 @@ func googleRequest(searchURL string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func googleResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
doc, err := goquery.NewDocumentFromResponse(response)
|
||||
doc, err := goquery.NewDocumentFromReader(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -34,23 +38,49 @@ func googleResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
results := []core.SearchResult{}
|
||||
rank := 1
|
||||
|
||||
// Get individual results
|
||||
sel := doc.Find("div.g")
|
||||
// Use data attributes instead of class names to find results
|
||||
// Both old and new DOM have data-hveid and data-ved attributes
|
||||
sel := doc.Find("div[data-hveid][data-ved]")
|
||||
|
||||
for i := range sel.Nodes {
|
||||
item := sel.Eq(i)
|
||||
|
||||
// Find URL
|
||||
linkTag := item.Find("a")
|
||||
link, _ := linkTag.Attr("href")
|
||||
// Skip items without an h3 element (which indicates a search result)
|
||||
if item.Find("h3").Length() == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Find URL - look for the anchor that contains the h3 title
|
||||
linkTag := item.Find("h3").Parent()
|
||||
if linkTag.Is("a") == false {
|
||||
linkTag = item.Find("h3").Closest("a")
|
||||
}
|
||||
|
||||
link, exists := linkTag.Attr("href")
|
||||
if !exists || link == "" || link == "#" {
|
||||
continue
|
||||
}
|
||||
link = strings.Trim(link, " ")
|
||||
|
||||
// Find title
|
||||
// Find title - this is inside the h3 element
|
||||
titleTag := item.Find("h3")
|
||||
title := titleTag.Text()
|
||||
|
||||
// Find description
|
||||
descTag := item.Find(`div[data-sncf~="1"]`)
|
||||
// Find description - find div with text content after the heading
|
||||
// Using attribute selectors that match the description container
|
||||
descTag := item.Find("div[data-sncf='1']").Find("div").First()
|
||||
if descTag.Length() == 0 {
|
||||
// Try another selector approach if the first one fails
|
||||
descTag = item.Find("div.VwiC3b")
|
||||
if descTag.Length() == 0 {
|
||||
// As a last resort, look for any div after the title that might contain description
|
||||
titleParent := titleTag.Parent()
|
||||
if titleParent.Is("a") {
|
||||
titleParent = titleParent.Parent().Parent()
|
||||
}
|
||||
descTag = titleParent.NextAll().First().Find("div").First()
|
||||
}
|
||||
}
|
||||
desc := descTag.Text()
|
||||
|
||||
if link != "" && link != "#" {
|
||||
@@ -67,7 +97,7 @@ func googleResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
}
|
||||
|
||||
logrus.Tracef("Google search document size: %d", len(doc.Text()))
|
||||
return results, err
|
||||
return core.DeduplicateResults(results), err
|
||||
}
|
||||
|
||||
func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
@@ -77,7 +107,7 @@ func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
logrus.Debugf("Google URL built: %s", googleURL)
|
||||
|
||||
res, err := googleRequest(googleURL)
|
||||
res, err := googleRequest(googleURL, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -87,6 +117,12 @@ func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if query.Start > 0 {
|
||||
for i := range results {
|
||||
results[i].Rank = query.Start + i + 1
|
||||
}
|
||||
}
|
||||
logrus.Debugf("Google Raw results : %v", results)
|
||||
|
||||
return results, nil
|
||||
|
||||
@@ -2,32 +2,8 @@ package google
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/karust/openserp/core"
|
||||
)
|
||||
|
||||
var browser *core.Browser
|
||||
|
||||
func init() {
|
||||
opts := core.BrowserOpts{IsHeadless: true, IsLeakless: false, Timeout: time.Second * 5, LeavePageOpen: false}
|
||||
browser, _ = core.NewBrowser(opts)
|
||||
}
|
||||
|
||||
func TestSearchGoogle(t *testing.T) {
|
||||
gogl := New(*browser, core.SearchEngineOptions{})
|
||||
|
||||
query := core.Query{Text: "HEY", Limit: 10}
|
||||
results, err := gogl.Search(query)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot [SearchGoogle]: %s", err)
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
t.Fatalf("[SearchGoogle] returned empty result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSourceImageURL(t *testing.T) {
|
||||
//href1 := `/imgres?imgurl=https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F2%2F26%2FMarmota_marmota_Alpes2.jpg&tbnid=Be_RycOe8xzlpM&vet=12ahUKEwjkh6WzwIeAAxWV_yoKHRzHC9wQMygAegUIARD0AQ..i&imgrefurl=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FAlpine_marmot&docid=7miWbc2QiSw9uM&w=801&h=599&q=alpine%20marmot&ved=2ahUKEwjkh6WzwIeAAxWV_yoKHRzHC9wQMygAegUIARD0AQ`
|
||||
href2 := `/imgres?imgurl=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fnaturerules1%2Fimages%2Ff%2Ff2%2F13d79d934ccf6f7919777fcb6dbb6e6c.jpg%2Frevision%2Flatest%3Fcb%3D20210218225522&tbnid=JxC8NUyBjdNbdM&vet=12ahUKEwiHrJnN1YeAAxXvEBAIHfRADAAQMygCegUIARD4AQ..i&imgrefurl=https%3A%2F%2Fnaturerules1.fandom.com%2Fwiki%2FAlpine_Marmot&docid=XXYeDjL67badNM&w=1600&h=1200&q=alpine%20marmot&ved=2ahUKEwiHrJnN1YeAAxXvEBAIHfRADAAQMygCegUIARD4AQ`
|
||||
@@ -47,21 +23,3 @@ func TestParseSourceImageURL(t *testing.T) {
|
||||
t.Fatalf("Want: %v, Got: %v", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageSearch(t *testing.T) {
|
||||
gogl := New(*browser, core.SearchEngineOptions{})
|
||||
query := core.Query{Text: "Ferrari Testarossa", Limit: 77}
|
||||
results, err := gogl.SearchImage(query)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot search images: %s", err)
|
||||
}
|
||||
|
||||
if len(results) < 77 {
|
||||
t.Fatalf("Returned not full result")
|
||||
}
|
||||
|
||||
if results[0].URL == "" {
|
||||
t.Fatalf("First result doesn't contain URL, %v+", results[0])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,6 +259,19 @@ func BuildURL(q core.Query) (string, error) {
|
||||
params.Add("num", strconv.Itoa(q.Limit))
|
||||
}
|
||||
|
||||
// Set result offset for pagination
|
||||
if q.Start < 0 {
|
||||
return "", errors.New("incorrect start param provided")
|
||||
}
|
||||
if q.Start > 0 {
|
||||
params.Add("start", strconv.Itoa(q.Start))
|
||||
}
|
||||
|
||||
// Google default is filter=1; send only when user asks to include similar results.
|
||||
if !q.Filter {
|
||||
params.Add("filter", "0")
|
||||
}
|
||||
|
||||
if q.LangCode != "" {
|
||||
params.Add("hl", q.LangCode)
|
||||
params.Add("lr", "lang_"+strings.ToLower(q.LangCode))
|
||||
|
||||
94
logo.svg
Normal file
94
logo.svg
Normal file
@@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 320" role="img" aria-labelledby="title desc">
|
||||
<title id="title">OpenSERP – Multi‑Engine API Logo</title>
|
||||
<desc id="desc">Professional banner-like logo with a unified search bar and chips for Google, Bing, DuckDuckGo, Yandex and Baidu, plus an API caption.</desc>
|
||||
|
||||
<defs>
|
||||
<linearGradient id="bar" x1="0" y1="0" x2="1" y2="0">
|
||||
<stop offset="0%" stop-color="#F5F7FB"/>
|
||||
<stop offset="100%" stop-color="#FFFFFF"/>
|
||||
</linearGradient>
|
||||
<filter id="shadow" x="-10%" y="-30%" width="120%" height="160%">
|
||||
<feDropShadow dx="0" dy="8" stdDeviation="12" flood-opacity="0.18"/>
|
||||
</filter>
|
||||
<filter id="soft" x="-20%" y="-20%" width="140%" height="140%">
|
||||
<feDropShadow dx="0" dy="2" stdDeviation="3" flood-opacity="0.18"/>
|
||||
</filter>
|
||||
<style>
|
||||
.muted{fill:#5F6B7A}
|
||||
.chip-label{font:700 14px Inter,Segoe UI,Arial,sans-serif;fill:#1F2937}
|
||||
.api{font:800 44px "Segoe UI",Inter,Arial,sans-serif;fill:#EA4335}
|
||||
.title{font:800 46px Inter,Segoe UI,Arial,sans-serif;letter-spacing:0.2px}
|
||||
</style>
|
||||
</defs>
|
||||
|
||||
<!-- Top brand title similar to the provided mock but neutral -->
|
||||
<g transform="translate(640,58)" text-anchor="middle">
|
||||
<text class="title" x="0" y="0">
|
||||
<tspan fill="#4285F4">O</tspan><tspan fill="#EA4335">p</tspan><tspan fill="#FBBC04">e</tspan><tspan fill="#4285F4">n</tspan><tspan fill="#34A853">S</tspan><tspan fill="#EA4335">E</tspan><tspan fill="#4285F4">R</tspan><tspan fill="#FBBC04">P</tspan>
|
||||
</text>
|
||||
</g>
|
||||
|
||||
<!-- Main unified search bar -->
|
||||
<g transform="translate(160,100)">
|
||||
<rect x="0" y="0" rx="28" ry="28" width="960" height="60" fill="url(#bar)" filter="url(#shadow)"/>
|
||||
<!-- left magnifier -->
|
||||
<g class="muted" transform="translate(22,18)">
|
||||
<circle cx="14" cy="14" r="10" fill="none" stroke="#98A2B3" stroke-width="3"/>
|
||||
<rect x="22" y="22" width="12" height="4" rx="2" fill="#98A2B3" transform="rotate(45 28 24)"/>
|
||||
</g>
|
||||
<!-- placeholder text -->
|
||||
<text x="70" y="37" font="500 18px Inter,Segoe UI,Arial" fill="#5F6B7A">Search across Google, Bing, DuckDuckGo, Yandex, Baidu…</text>
|
||||
<!-- right icons -->
|
||||
<g transform="translate(880,13)" class="muted">
|
||||
<rect x="48" y="-2" width="1" height="36" fill="#E5E7EB"/>
|
||||
<circle cx="18" cy="17" r="8" fill="#E5E7EB"/>
|
||||
<rect x="12" y="8" width="12" height="6" rx="3" fill="#98A2B3"/>
|
||||
<circle cx="18" cy="17" r="3" fill="#98A2B3"/>
|
||||
<!-- microphone glyph -->
|
||||
<rect x="62" y="6" width="8" height="16" rx="4" fill="#98A2B3"/>
|
||||
<rect x="60" y="24" width="12" height="3" rx="1.5" fill="#98A2B3"/>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- Engine chips (brand colored, accessible, non-trademark glyphs) -->
|
||||
<g transform="translate(640,88)" text-anchor="middle" dominant-baseline="middle">
|
||||
<!-- layout positions -->
|
||||
<g transform="translate(-420,-8)">
|
||||
<rect rx="14" ry="14" width="120" height="28" fill="#FFFFFF" stroke="#E5E7EB" filter="url(#soft)"/>
|
||||
<circle cx="16" cy="14" r="8" fill="#4285F4"/>
|
||||
<text class="chip-label" x="78" y="17">Google</text>
|
||||
</g>
|
||||
|
||||
<g transform="translate(-260,-8)">
|
||||
<rect rx="14" ry="14" width="110" height="28" fill="#FFFFFF" stroke="#E5E7EB" filter="url(#soft)"/>
|
||||
<circle cx="16" cy="14" r="8" fill="#008373"/>
|
||||
<text class="chip-label" x="70" y="17">Bing</text>
|
||||
</g>
|
||||
|
||||
<g transform="translate(-100,-8)">
|
||||
<rect rx="14" ry="14" width="150" height="28" fill="#FFFFFF" stroke="#E5E7EB" filter="url(#soft)"/>
|
||||
<circle cx="16" cy="14" r="8" fill="#DE5833"/>
|
||||
<text class="chip-label" x="90" y="17">DuckDuckGo</text>
|
||||
</g>
|
||||
|
||||
<g transform="translate(90,-8)">
|
||||
<rect rx="14" ry="14" width="120" height="28" fill="#FFFFFF" stroke="#E5E7EB" filter="url(#soft)"/>
|
||||
<circle cx="16" cy="14" r="8" fill="#FC3F1D"/>
|
||||
<text class="chip-label" x="78" y="17">Yandex</text>
|
||||
</g>
|
||||
|
||||
<g transform="translate(250,-8)">
|
||||
<rect rx="14" ry="14" width="115" height="28" fill="#FFFFFF" stroke="#E5E7EB" filter="url(#soft)"/>
|
||||
<circle cx="16" cy="14" r="8" fill="#2932E1"/>
|
||||
<text class="chip-label" x="72" y="17">Baidu</text>
|
||||
</g>
|
||||
</g>
|
||||
|
||||
<!-- API caption -->
|
||||
<g transform="translate(640,232)" text-anchor="middle">
|
||||
<text class="api">API</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 4.3 KiB |
25
testutil/integration.go
Normal file
25
testutil/integration.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const IntegrationEnv = "OPENSERP_INTEGRATION_TESTS"
|
||||
|
||||
func RequireIntegration(t *testing.T) {
|
||||
t.Helper()
|
||||
if strings.TrimSpace(os.Getenv(IntegrationEnv)) != "1" {
|
||||
t.Skipf("set %s=1 to run integration tests", IntegrationEnv)
|
||||
}
|
||||
}
|
||||
|
||||
func RequireEnv(t *testing.T, key string) string {
|
||||
t.Helper()
|
||||
value := strings.TrimSpace(os.Getenv(key))
|
||||
if value == "" {
|
||||
t.Skipf("set %s to run this integration test", key)
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/karust/openserp/core"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
@@ -38,12 +37,14 @@ type Yandex struct {
|
||||
core.Browser
|
||||
core.SearchEngineOptions
|
||||
pageSleep time.Duration // Sleep between pages
|
||||
logger *core.EngineLogger
|
||||
}
|
||||
|
||||
func New(browser core.Browser, opts core.SearchEngineOptions) *Yandex {
|
||||
yand := Yandex{Browser: browser}
|
||||
opts.Init()
|
||||
yand.SearchEngineOptions = opts
|
||||
yand.logger = core.NewEngineLogger("Yandex")
|
||||
|
||||
yand.pageSleep = time.Second * 1
|
||||
return &yand
|
||||
@@ -80,19 +81,19 @@ func (yand *Yandex) parseResults(results rod.Elements, pageNum int) []core.Searc
|
||||
}
|
||||
linkText, err := link.Property("href")
|
||||
if err != nil {
|
||||
logrus.Error("No `href` tag found")
|
||||
yand.logger.Error("Missing href")
|
||||
}
|
||||
|
||||
// Get title
|
||||
titleTag, err := link.Element("h2")
|
||||
if err != nil {
|
||||
logrus.Error("No title `h2` tag found")
|
||||
yand.logger.Error("Missing h2 title")
|
||||
continue
|
||||
}
|
||||
|
||||
title, err := titleTag.Text()
|
||||
if err != nil {
|
||||
logrus.Error("Cannot extract text from title")
|
||||
yand.logger.Error("Failed to extract title")
|
||||
title = "No title"
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ func (yand *Yandex) parseResults(results rod.Elements, pageNum int) []core.Searc
|
||||
descTag, err := r.Element(`span.OrganicTextContentSpan`)
|
||||
desc := ""
|
||||
if err != nil {
|
||||
logrus.Trace("No description `span.OrganicTextContentSpan` tag found")
|
||||
yand.logger.Debug("No description")
|
||||
} else {
|
||||
desc = descTag.MustText()
|
||||
}
|
||||
@@ -113,10 +114,18 @@ func (yand *Yandex) parseResults(results rod.Elements, pageNum int) []core.Searc
|
||||
}
|
||||
|
||||
func (yand *Yandex) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Yandex search, query: %+v", query)
|
||||
yand.logger.Debug("Starting search, query: %+v", query)
|
||||
if query.Start < 0 {
|
||||
return nil, fmt.Errorf("incorrect start provided")
|
||||
}
|
||||
|
||||
allResults := []core.SearchResult{}
|
||||
searchPage := 0
|
||||
const pageSize = 10
|
||||
searchPage, skipOnFirstPage, err := core.ComputePagination(query.Start, pageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
startPage := searchPage
|
||||
|
||||
for len(allResults) < query.Limit {
|
||||
url, err := BuildURL(query, searchPage)
|
||||
@@ -124,13 +133,16 @@ func (yand *Yandex) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
page := yand.Navigate(url)
|
||||
page, err := yand.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get all search results in page
|
||||
searchRes, err := page.Timeout(yand.Timeout).Search("li.serp-item")
|
||||
if err != nil {
|
||||
defer page.Close()
|
||||
logrus.Errorf("Cannot parse search results: %s", err)
|
||||
yand.logger.Error("Cannot parse search results: %s", err)
|
||||
return nil, core.ErrSearchTimeout
|
||||
}
|
||||
|
||||
@@ -139,9 +151,9 @@ func (yand *Yandex) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
defer page.Close()
|
||||
|
||||
if yand.isNoResults(page) {
|
||||
logrus.Errorf("No results found")
|
||||
yand.logger.Warn("No results found")
|
||||
} else if yand.isCaptcha(page) {
|
||||
logrus.Errorf("Yandex captcha occurred during: %s", url)
|
||||
yand.logger.Error("Captcha detected: %s", url)
|
||||
return nil, core.ErrCaptcha
|
||||
}
|
||||
break
|
||||
@@ -149,11 +161,18 @@ func (yand *Yandex) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
elements, err := searchRes.All()
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot get all elements from search results: %s", err)
|
||||
yand.logger.Error("Cannot get search elements: %s", err)
|
||||
break
|
||||
}
|
||||
|
||||
r := yand.parseResults(elements, searchPage)
|
||||
if searchPage == startPage && skipOnFirstPage > 0 {
|
||||
if skipOnFirstPage >= len(r) {
|
||||
r = []core.SearchResult{}
|
||||
} else {
|
||||
r = r[skipOnFirstPage:]
|
||||
}
|
||||
}
|
||||
allResults = append(allResults, r...)
|
||||
|
||||
searchPage++
|
||||
@@ -162,18 +181,19 @@ func (yand *Yandex) Search(query core.Query) ([]core.SearchResult, error) {
|
||||
// Close tab before opening new one during the cycle
|
||||
err = page.Close()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
yand.logger.Debug("Page close error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(yand.pageSleep)
|
||||
}
|
||||
|
||||
return allResults, nil
|
||||
yand.logger.Info("Search completed: %d results", len(allResults))
|
||||
return core.DeduplicateResults(allResults), nil
|
||||
}
|
||||
|
||||
func (yand *Yandex) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
logrus.Tracef("Start Yandex image search, query: %+v", query)
|
||||
yand.logger.Debug("Starting image search, query: %+v", query)
|
||||
|
||||
searchResults := []core.SearchResult{}
|
||||
|
||||
@@ -185,9 +205,12 @@ func (yand *Yandex) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
}
|
||||
searchPage += 1
|
||||
|
||||
page := yand.Navigate(url)
|
||||
page, err := yand.Navigate(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !yand.LeavePageOpen {
|
||||
if !yand.Browser.LeavePageOpen {
|
||||
defer page.Close()
|
||||
}
|
||||
|
||||
@@ -197,16 +220,16 @@ func (yand *Yandex) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
|
||||
results, err := page.Timeout(yand.Timeout).Search("div[role='main'] div[data-state]")
|
||||
if err != nil {
|
||||
logrus.Errorf("Cannot find search results: %s", err)
|
||||
yand.logger.Error("Cannot find search results: %s", err)
|
||||
}
|
||||
|
||||
// Check why no results
|
||||
if results == nil {
|
||||
if yand.isCaptcha(page) {
|
||||
logrus.Errorf("Yandex captcha occurred during: %s", url)
|
||||
yand.logger.Error("Captcha detected: %s", url)
|
||||
return searchResults, core.ErrCaptcha
|
||||
} else if yand.isNoResults(page) {
|
||||
logrus.Errorf("No results found")
|
||||
yand.logger.Warn("No results found")
|
||||
}
|
||||
return searchResults, core.ErrSearchTimeout
|
||||
}
|
||||
@@ -233,7 +256,7 @@ func (yand *Yandex) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
searchResults = append(searchResults, res)
|
||||
}
|
||||
|
||||
if !yand.LeavePageOpen {
|
||||
if !yand.Browser.LeavePageOpen {
|
||||
page.Close()
|
||||
}
|
||||
}
|
||||
@@ -242,5 +265,5 @@ func (yand *Yandex) SearchImage(query core.Query) ([]core.SearchResult, error) {
|
||||
return searchResults[i].Rank < searchResults[j].Rank
|
||||
})
|
||||
|
||||
return searchResults, nil
|
||||
return core.DeduplicateResults(searchResults), nil
|
||||
}
|
||||
|
||||
@@ -10,8 +10,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func yandexRequest(searchURL string) (*http.Response, error) {
|
||||
baseClient := &http.Client{}
|
||||
func yandexRequest(searchURL string, query core.Query) (*http.Response, error) {
|
||||
baseClient, err := core.NewRawHTTPClient(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", searchURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -26,7 +30,7 @@ func yandexRequest(searchURL string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func yandexResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
doc, err := goquery.NewDocumentFromResponse(response)
|
||||
doc, err := goquery.NewDocumentFromReader(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,17 +71,22 @@ func yandexResultParser(response *http.Response) ([]core.SearchResult, error) {
|
||||
}
|
||||
|
||||
logrus.Tracef("Yandex search document size: %d", len(doc.Text()))
|
||||
return results, err
|
||||
return core.DeduplicateResults(results), err
|
||||
}
|
||||
|
||||
func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
googleURL, err := BuildURL(query, 1)
|
||||
startPage, skipOnFirstPage, err := core.ComputePagination(query.Start, 10)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
googleURL, err := BuildURL(query, startPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logrus.Debugf("Yandex URL built: %s", googleURL)
|
||||
|
||||
res, err := yandexRequest(googleURL)
|
||||
res, err := yandexRequest(googleURL, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -87,6 +96,19 @@ func Search(query core.Query) ([]core.SearchResult, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if skipOnFirstPage > 0 {
|
||||
if skipOnFirstPage >= len(results) {
|
||||
results = []core.SearchResult{}
|
||||
} else {
|
||||
results = results[skipOnFirstPage:]
|
||||
}
|
||||
}
|
||||
if query.Start > 0 {
|
||||
for i := range results {
|
||||
results[i].Rank = query.Start + i + 1
|
||||
}
|
||||
}
|
||||
logrus.Debugf("Yandex Raw results : %v", results)
|
||||
|
||||
return results, nil
|
||||
|
||||
Reference in New Issue
Block a user