From 5a166132e094e9c6d253d9de83af542bfbe80d07 Mon Sep 17 00:00:00 2001 From: John Pedrie Date: Tue, 5 Mar 2024 13:42:09 -0500 Subject: [PATCH] add spellcheck toggle option (#5) --- brave.go | 42 +++++++++++++++++++++++++----------------- web.go | 2 ++ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/brave.go b/brave.go index 235e242..f4a57d5 100644 --- a/brave.go +++ b/brave.go @@ -187,30 +187,31 @@ const ( type SearchOption func(searchOptions) searchOptions type searchOptions struct { - country string - lang string - uiLang string count int - offset int - safesearch Safesearch - freshness Freshness + country string customFreshness []time.Time - textDecorations bool - resultFilter []ResultFilter - gogglesID string - units UnitType extraSnippets bool - rich bool - noCache bool - userAgent string + freshness Freshness + gogglesID string + lang string + locCity string + locCountry string locLatitude *float32 locLongitude *float32 - locTimezone *time.Location - locCity string + locPostalCode string locState string locStateName string - locCountry string - locPostalCode string + locTimezone *time.Location + noCache bool + offset int + resultFilter []ResultFilter + rich bool + safesearch Safesearch + spellcheck *bool + textDecorations bool + uiLang string + units UnitType + userAgent string } func (s searchOptions) getFreshness() string { @@ -637,6 +638,13 @@ func WithLocPostalCode(v string) SearchOption { } } +func WithSpellcheck(v bool) SearchOption { + return func(o searchOptions) searchOptions { + o.spellcheck = &v + return o + } +} + // ClientOption allows configuration of the API client. type ClientOption func(clientOptions) clientOptions diff --git a/web.go b/web.go index 4a2d77e..1d47da6 100644 --- a/web.go +++ b/web.go @@ -57,6 +57,7 @@ type webSearchParams struct { ResultFilter []string `url:"result_filter,omitempty,comma"` Safesearch string `url:"safesearch,omitempty"` SearchLang string `url:"search_lang,omitempty"` + Spellcheck *bool `url:"spellcheck,omitempty"` Term string `url:"q"` TextDecorations bool `url:"text_decorations,omitempty"` UILang string `url:"ui_lang,omitempty"` @@ -73,6 +74,7 @@ func (w *webSearchParams) fromSearchOptions(term string, options searchOptions) w.ResultFilter = options.getResultFilter() w.Safesearch = options.safesearch.String() w.SearchLang = options.lang + w.Spellcheck = options.spellcheck w.Term = term w.TextDecorations = options.textDecorations w.UILang = options.uiLang