initial commit

This commit is contained in:
2024-11-08 20:51:12 -05:00
commit 98fa840f87
8 changed files with 739 additions and 0 deletions

44
pkg/search/google.go Normal file
View File

@@ -0,0 +1,44 @@
package search
import (
"context"
googlesearch "github.com/rocketlaunchr/google-search"
"sort"
)
type Google struct {
}
var _ Search = Google{}
func (Google) Search(ctx context.Context, search string) ([]Result, error) {
res, err := googlesearch.Search(ctx, search, googlesearch.SearchOptions{
CountryCode: "",
LanguageCode: "",
Limit: 0,
Start: 0,
UserAgent: "",
OverLimit: false,
ProxyAddr: "",
FollowNextPage: false,
})
if err != nil {
return nil, err
}
var results []Result
// just in case, sort the res by rank, as the api does not mention it is sorted
sort.Slice(res, func(i, j int) bool {
return res[i].Rank < res[j].Rank
})
for _, r := range res {
results = append(results, Result{
Title: r.Title,
URL: r.URL,
Description: r.Description,
})
}
}