initial commit
This commit is contained in:
44
pkg/search/google.go
Normal file
44
pkg/search/google.go
Normal 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,
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user