-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
47 lines (35 loc) · 1010 Bytes
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package brave
import (
"context"
"net/http"
"github.com/google/go-querystring/query"
)
func (b *brave) ImageSearch(ctx context.Context, term string, options ...SearchOption) (*ImageSearchResult, error) {
u := *b.baseURL
u.Path = u.Path + imageSearchPath
var opts searchOptions
applyOpts(&opts, options, func(o searchOptions) searchOptions {
// image search does not support moderate, default to strict.
if o.safesearch == SafesearchModerate {
o.safesearch = SafesearchStrict
}
return o
})
var params webSearchParams
params.fromSearchOptions(term, opts)
values, err := query.Values(params)
if err != nil {
return nil, err
}
u.RawQuery = values.Encode()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
opts.applyRequestHeaders(b.subscriptionToken, req)
return handleRequest[ImageSearchResult](b.client, req)
}
type ImageSearchResult struct {
ResultContainer[ImageResult]
Query *Query `json:"query"`
}