Documentation ¶
Index ¶
- type Answer
- type Article
- type Book
- type Brave
- type ButtonResult
- type ClientOption
- type Contact
- type CreativeWork
- type DataProvider
- type DayOpeningHours
- type DeepResult
- type DiscussionResult
- type Duration
- type ErrorContext
- type ErrorMeta
- type ErrorMetaError
- type ErrorResponse
- type FAQ
- type ForumData
- type Freshness
- type GraphInfoBox
- type HowTo
- type Image
- type ImageProperties
- type ImageResult
- type ImageSearchResult
- type KnowledgeGraphEntity
- type KnowledgeGraphProfile
- type Language
- type LocationResult
- type MetaURL
- type Mixed
- type MobileURLItem
- type MovieData
- type MusicRecording
- type NewsResult
- type Number
- type Offer
- type OpeningHours
- type Organization
- type Person
- type PictureResults
- type PostalAddress
- type Price
- type Product
- type Profile
- type QA
- type QAPage
- type Query
- type Rating
- type Recipe
- type Result
- type ResultContainer
- type ResultFilter
- type ResultReference
- type Review
- type Reviews
- type Safesearch
- type SearchOption
- func WithAPIVersion(v string) SearchOption
- func WithCount(v int) SearchOption
- func WithCountry(v string) SearchOption
- func WithCustomFreshness(start time.Time, end time.Time) SearchOption
- func WithEntityInfo(v bool) SearchOption
- func WithExtraSnippets(v bool) SearchOption
- func WithFreshness(v Freshness) SearchOption
- func WithGogglesID(v string) SearchOption
- func WithLang(v string) SearchOption
- func WithLocCity(v string) SearchOption
- func WithLocCountry(v string) SearchOption
- func WithLocLatitude(v float32) SearchOption
- func WithLocLongitude(v float32) SearchOption
- func WithLocPostalCode(v string) SearchOption
- func WithLocState(v string) SearchOption
- func WithLocStateName(v string) SearchOption
- func WithLocTimezone(v *time.Location) SearchOption
- func WithNoCache(v bool) SearchOption
- func WithOffset(v int) SearchOption
- func WithResultFilter(v ...ResultFilter) SearchOption
- func WithRich(v bool) SearchOption
- func WithSafesearch(v Safesearch) SearchOption
- func WithSpellcheck(v bool) SearchOption
- func WithSummary(v bool) SearchOption
- func WithTextDecorations(v bool) SearchOption
- func WithUILang(v string) SearchOption
- func WithUnits(v UnitType) SearchOption
- func WithUserAgent(v string) SearchOption
- type SearchResult
- type Software
- type SpellcheckResult
- type SpellcheckResultItem
- type SuggestResult
- type SuggestSearchResult
- type Summarizer
- type SummarizerSearchResult
- type SummaryAnswer
- type SummaryContext
- type SummaryEnrichments
- type SummaryEntity
- type SummaryMessage
- type TextLocation
- type Thumbnail
- type Timestamp
- type TripAdvisorReview
- type URL
- type Unit
- type UnitType
- type VideoData
- type VideoResult
- type VideoSearchResult
- type VideoViews
- type WebSearchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Article ¶
type Article struct { Author []Person `json:"author"` Date string `json:"date"` Publisher *Organization `json:"publisher"` Thumbnail *Thumbnail `json:"thumbnail"` IsAccessibleForFree bool `json:"isAccessibleForFree"` }
type Brave ¶
type Brave interface { // WebSearch returns web search results. WebSearch(ctx context.Context, term string, options ...SearchOption) (*WebSearchResult, error) // SuggestSearch returns suggested related search terms. SuggestSearch(ctx context.Context, term string, options ...SearchOption) (*SuggestSearchResult, error) // Spellcheck returns spelling suggestions. Spellcheck(ctx context.Context, term string, options ...SearchOption) (*SpellcheckResult, error) // ImageSearch returns image search results. ImageSearch(ctx context.Context, term string, options ...SearchOption) (*ImageSearchResult, error) // VideoSearch returns video search results. VideoSearch(ctx context.Context, term string, options ...SearchOption) (*VideoSearchResult, error) // SummarizerSearch returns AI summaries of a search result. SummarizerSearch(ctx context.Context, key string, options ...SearchOption) (*SummarizerSearchResult, error) }
Brave is an interface for fetching results from the Brave Search API.
type ButtonResult ¶
type ClientOption ¶
type ClientOption func(clientOptions) clientOptions
ClientOption allows configuration of the API client.
func WithBaseURL ¶
func WithBaseURL(v string) ClientOption
WithBaseURL overrides the default URL of the Brave API client. This is especially useful for testing.
func WithHTTPClient ¶
func WithHTTPClient(v *http.Client) ClientOption
WithHTTPClient allows overriding of the HTTP client used to make requests to the Brave API.
If not provided, defaults to http.DefaultClient.
type CreativeWork ¶
type DataProvider ¶
type DayOpeningHours ¶
type DeepResult ¶
type DeepResult struct { News []NewsResult `json:"news"` Buttons []ButtonResult `json:"buttons"` Social []KnowledgeGraphProfile `json:"social"` Videos []VideoResult `json:"videos"` Images []Image `json:"images"` }
type DiscussionResult ¶
type DiscussionResult struct { SearchResult Type string `json:"type"` Data ForumData `json:"data"` }
type Duration ¶
func (*Duration) UnmarshalJSON ¶
type ErrorContext ¶
type ErrorContext struct {
EnumValues []string `json:"enum_values"`
}
type ErrorMeta ¶
type ErrorMeta struct { Component string `json:"component"` Errors []ErrorMetaError `json:"errors"` }
type ErrorMetaError ¶
type ErrorMetaError struct { Loc []string `json:"loc"` Message string `json:"msg"` Type string `json:"type"` Context ErrorContext `json:"ctx"` Input string `json:"input"` }
type ErrorResponse ¶
type ErrorResponse struct { ID string `json:"id"` Status int `json:"status"` Code string `json:"code"` Detail string `json:"detail"` Meta ErrorMeta `json:"meta"` RawQuery string `json:"raw_query"` Time *Timestamp `json:"-"` }
func (ErrorResponse) Error ¶
func (er ErrorResponse) Error() string
type Freshness ¶
type Freshness int8
Freshness filters search results by when they were discovered.
Refer to Query Parameters for more detail.
type GraphInfoBox ¶
type GraphInfoBox struct { Result Type string `json:"type"` Position int `json:"position"` Label string `json:"label"` Category string `json:"category"` LongDesc string `json:"long_desc"` Thumbnail *Thumbnail `json:"thumbnail"` Attributes []any `json:"attributes"` Profiles []Profile `json:"profiles"` WebsiteURL string `json:"website_url"` AttributesShown int `json:"attributes_shown"` Ratings []Rating `json:"ratings"` Providers []DataProvider `json:"providers"` Distance *Unit `json:"distance"` Images []Thumbnail `json:"images"` Movie *MovieData `json:"movie"` }
type Image ¶
type Image struct { Thumbnail *Thumbnail `json:"thumbnail"` URL string `json:"url"` Properties *ImageProperties `json:"properties"` Text string `json:"text"` }
type ImageProperties ¶
type ImageResult ¶
type ImageResult struct { Type string `json:"type"` Title string `json:"title"` URL string `json:"url"` Source string `json:"source"` PageFetched *Timestamp `json:"page_fetched"` Thumbnail *Thumbnail `json:"thumbnail"` Properties *ImageProperties `json:"properties"` MetaURL *MetaURL `json:"meta_url"` }
type ImageSearchResult ¶
type ImageSearchResult struct { ResultContainer[ImageResult] Query *Query `json:"query"` }
type KnowledgeGraphEntity ¶
type KnowledgeGraphProfile ¶
type KnowledgeGraphProfile struct { KnowledgeGraphEntity URL string `json:"url"` Description string `json:"description"` }
type LocationResult ¶
type LocationResult struct { Result Type string `json:"type"` ProviderURL string `json:"provider_url"` Coordinates []float32 `json:"coordinates"` ZoomLevel int `json:"zoom_level"` Thumbnail *Thumbnail `json:"thumbnail"` PostalAddress *PostalAddress `json:"postal_address"` OpeningHours *OpeningHours `json:"opening_hours"` Contact *Contact `json:"contact"` PriceRange string `json:"price_range"` Rating *Rating `json:"rating"` Distance *Unit `json:"distance"` Profiles []DataProvider `json:"profiles"` Reviews *Reviews `json:"reviews"` Pictures *PictureResults `json:"pictures"` ServesCuisine []string `json:"serves_cuisine"` Timezone string `json:"timezone"` TimezoneOffset float32 `json:"timezone_offset"` }
type Mixed ¶
type Mixed struct { Type string `json:"type"` Main []ResultReference Top []ResultReference Side []ResultReference }
type MobileURLItem ¶
type MusicRecording ¶
type NewsResult ¶
type OpeningHours ¶
type OpeningHours struct { CurrentDay []DayOpeningHours `json:"current_day"` Days [][]DayOpeningHours `json:"days"` }
type Organization ¶
type PictureResults ¶
type PostalAddress ¶
type PostalAddress struct { Type string `json:"type"` Country string `json:"country"` PostalCode string `json:"postalCode"` StreetAddress string `json:"streetAddress"` AddressRegion string `json:"addressRegion"` AddressLocality string `json:"addressLocality"` DisplayAddress string `json:"displayAddress"` }
type Query ¶
type Query struct { Original string `json:"original"` ShowStrictWarning bool `json:"show_strict_warning"` Altered string `json:"altered"` Safesearch bool `json:"safesearch"` IsGeolocal bool `json:"is_geolocal"` LocalDecision string `json:"local_decision"` LocalLocationsIdx int `json:"local_locations_idx"` IsTrending bool `json:"is_trending"` IsNewsBreaking bool `json:"is_news_breaking"` AskForLocation bool `json:"ask_for_location"` Language *Language `json:"language"` SpellcheckOff bool `json:"spellcheck_off"` Country string `json:"country"` BadResults bool `json:"bad_results"` ShouldFallback bool `json:"should_fallback"` Lat string `json:"lat"` Long string `json:"long"` PostalCode string `json:"postal_code"` City string `json:"city"` State string `json:"state"` HeaderCountry string `json:"header_country"` MoreResultsAvailable bool `json:"more_results_available"` CustomLocationLabel string `json:"custom_location_label"` RedditCluster string `json:"reddit_cluster"` SummaryKey string `json:"summary_key"` }
type Recipe ¶ added in v0.3.0
type Recipe struct { Title string `json:"title"` Description string `json:"description"` Thumbnail *Thumbnail `json:"thumbnail"` URL string `json:"url"` Domain string `json:"domain"` Favicon string `json:"favicon"` Time *Duration `json:"time"` PrepTime *Duration `json:"prep_time"` CookTime *Duration `json:"cook_time"` Ingredients string `json:"ingredients"` Instructions []HowTo `json:"instructions"` Servings int `json:"servings"` Calories int `json:"calories"` Rating *Rating `json:"rating"` RecipeCategory string `json:"recipeCategory"` RecipeCuisine string `json:"recipeCuisine"` Video *VideoData `json:"video"` }
type Result ¶
type Result struct { Title string `json:"title"` URL string `json:"url"` IsSourceLocal bool `json:"is_source_local"` IsSourceBoth bool `json:"is_source_both"` Description string `json:"description"` PageAge *Timestamp `json:"page_age"` PageFetched string `json:"page_fetched"` Profile *Profile `json:"profile"` Language string `json:"language"` FamilyFriendly bool `json:"family_friendly"` }
type ResultContainer ¶
type ResultFilter ¶
type ResultFilter string
ResultFilter controls the returned data from WebSearch.
Refer to Query Parameters for more detail.
const ( ResultFilterDiscussions ResultFilter = "discussions" ResultFilterFAQ ResultFilter = "faq" ResultFilterInfoBox ResultFilter = "infobox" ResultFilterNews ResultFilter = "news" ResultFilterVideos ResultFilter = "videos" ResultFilterWeb ResultFilter = "web" ResultFilterImages ResultFilter = "images" )
func (ResultFilter) String ¶
func (r ResultFilter) String() string
type ResultReference ¶
type Reviews ¶
type Reviews struct { Results []TripAdvisorReview `json:"results"` ViewMoreURL string `json:"viewMoreUrl"` ReviewsInForeignLanguage bool `json:"reviews_in_foreign_language"` }
type Safesearch ¶
type Safesearch int8
Safesearch controls the adult content filter. Defaults to `SafesearchModerate`.
Refer to Query Parameters for more detail.
const ( SafesearchModerate Safesearch = iota SafesearchOff SafesearchStrict )
func (Safesearch) String ¶
func (s Safesearch) String() string
type SearchOption ¶
type SearchOption func(searchOptions) searchOptions
SearchOption allows for setting optional arguments in requests.
func WithAPIVersion ¶ added in v0.1.7
func WithAPIVersion(v string) SearchOption
WithAPIVersion specifies the version of the API to use for a request.
Refer to Query Headers for more detail.
func WithCount ¶
func WithCount(v int) SearchOption
WithCount specifies the number of search results returned in response.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch].
Refer to Query Parameters for more detail.
func WithCountry ¶
func WithCountry(v string) SearchOption
WithCountry specifies the search query country, where the results come from.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Parameters for more detail.
func WithCustomFreshness ¶
func WithCustomFreshness(start time.Time, end time.Time) SearchOption
WithCustomFreshness filters search results by a specified timeframe in which the result was discovered. To use a known value, use WithFreshness.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithEntityInfo ¶ added in v0.2.0
func WithEntityInfo(v bool) SearchOption
WithEntityInfo specifies whether entity information should be returned
Applicable to [Brave.SummarizerSearch].
Refer to Query Parameters for more detail.
func WithExtraSnippets ¶
func WithExtraSnippets(v bool) SearchOption
WithExtraSnippets specifies whether to return extra alternate snippets for web search results. Defaults to `false`.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithFreshness ¶
func WithFreshness(v Freshness) SearchOption
WithFreshness filters search results by when they were discovered. To set a custom timeframe, use WithCustomFreshness.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithGogglesID ¶
func WithGogglesID(v string) SearchOption
WithGogglesID specifies a goggle URL to rerank search results.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithLang ¶
func WithLang(v string) SearchOption
WithLang specifies the search language preference.
Applicable to [Brave.WebSearch] (as `search_lang`), [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Parameters for more detail.
func WithLocCity ¶
func WithLocCity(v string) SearchOption
WithLocCity sets the generic name of the client city.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocCountry ¶
func WithLocCountry(v string) SearchOption
WithLocCountry sets the client country. Provide a two-letter country code, e.g. `US`.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocLatitude ¶
func WithLocLatitude(v float32) SearchOption
WithLocLatitude sets the latitude of the client's geographical location.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocLongitude ¶
func WithLocLongitude(v float32) SearchOption
WithLocLongitude sets the longitude of the client's geographical location.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocPostalCode ¶
func WithLocPostalCode(v string) SearchOption
WithLocPostalCode sets the client postal code.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocState ¶
func WithLocState(v string) SearchOption
WithLocState sets the client state or region. Provide a two- or three-character value, e.g. `MI`.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocStateName ¶
func WithLocStateName(v string) SearchOption
WithLocStateName sets the name of the client state or region.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithLocTimezone ¶
func WithLocTimezone(v *time.Location) SearchOption
WithLocTimezone sets the timezone of the client.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithNoCache ¶
func WithNoCache(v bool) SearchOption
WithNoCache specifies whether to disable server caching of results. Defaults to `false`.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
func WithOffset ¶
func WithOffset(v int) SearchOption
WithOffset specifies the zero based offset that indicates number of search result per page (count) to skip before returning the result.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithResultFilter ¶
func WithResultFilter(v ...ResultFilter) SearchOption
WithResultFilter specifies a list of result types to include in the search response.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithRich ¶
func WithRich(v bool) SearchOption
WithRich specifies whether to enhance suggestions with rich results. Defaults to `false`.
Applicable to [Brave.SuggestSearch].
Refer to Query Parameters for more detail.
func WithSafesearch ¶
func WithSafesearch(v Safesearch) SearchOption
WithSafesearch filters search results for adult content.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithSpellcheck ¶ added in v0.1.4
func WithSpellcheck(v bool) SearchOption
WithSpellcheck toggles spellchecking on or off.
Refer to Query Parameters for more detail.
func WithSummary ¶ added in v0.2.0
func WithSummary(v bool) SearchOption
WithSummary specifies whether a summary key should be requested.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithTextDecorations ¶
func WithTextDecorations(v bool) SearchOption
WithTextDecorations controls whether display strings, such as result snippets, should include decoration markers, such as highlighting characters. The default is true.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithUILang ¶
func WithUILang(v string) SearchOption
WithUILang specifies the user interface language preferred in response.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithUnits ¶
func WithUnits(v UnitType) SearchOption
WithUnits specifies the system of measurement.
Applicable to [Brave.WebSearch].
Refer to Query Parameters for more detail.
func WithUserAgent ¶
func WithUserAgent(v string) SearchOption
WithUserAgent sets the user agent of the client. Defaults to `false`.
Applicable to [Brave.WebSearch], [Brave.SuggestSearch], [Brave.Spellcheck].
Refer to Query Headers for more detail.
type SearchResult ¶
type SearchResult struct { Result Type string `json:"type"` DeepResults *DeepResult `json:"deep_results"` Schemas any `json:"schemas"` MetaURL MetaURL `json:"meta_url"` Thumbnail *Thumbnail `json:"thumbnail"` Age *Timestamp `json:"age"` Language string `json:"language"` ContentType string `json:"content_type"` Subtype string `json:"subtype"` Article *Article `json:"article"` Book *Book `json:"book"` Cluster []Result `json:"cluster"` ClusterType string `json:"cluster_type"` CreativeWork *CreativeWork `json:"creative_work"` FAQ *FAQ `json:"faq"` Location *LocationResult `json:"location"` Movie *MovieData `json:"movie"` MusicRecording *MusicRecording `json:"music_recording"` ProductCluster []Product `json:"product_cluster"` QA *QAPage `json:"qa"` Rating *Rating `json:"rating"` Recipe *Recipe `json:"recipe"` Review *Review `json:"review"` Software *Software `json:"software"` Video *VideoData `json:"video"` }
type SpellcheckResult ¶
type SpellcheckResult struct { Type string `json:"type"` Query *Query `json:"query"` Results []SpellcheckResultItem `json:"results"` }
type SpellcheckResultItem ¶
type SpellcheckResultItem struct {
Query string `json:"query"`
}
type SuggestResult ¶
type SuggestSearchResult ¶
type SuggestSearchResult struct { Type string `json:"type"` Query *Query `json:"query"` Results []SuggestResult `json:"results"` }
type Summarizer ¶ added in v0.2.0
type SummarizerSearchResult ¶ added in v0.1.7
type SummarizerSearchResult struct { Type string `json:"type"` Status string `json:"status"` Title string `json:"title"` Summary []SummaryMessage `json:"summary"` Enrichments *SummaryEnrichments `json:"enrichments"` Followups []string `json:"followups"` EntitiesInfo map[string]any `json:"entities_info"` }
type SummaryAnswer ¶ added in v0.2.0
type SummaryAnswer struct { Answer string `json:"answer"` Score float32 `json:"score"` Highlight *TextLocation `json:"highlight"` }
type SummaryContext ¶ added in v0.2.0
type SummaryEnrichments ¶ added in v0.2.0
type SummaryEnrichments struct { Raw string `json:"raw"` Images []Image `json:"images"` QA []SummaryAnswer `json:"qa"` Entities []SummaryEntity `json:"entities"` Context []SummaryContext `json:"context"` }
type SummaryEntity ¶ added in v0.2.0
type SummaryMessage ¶ added in v0.2.0
type TextLocation ¶ added in v0.2.0
type Timestamp ¶
func (*Timestamp) UnmarshalJSON ¶
type TripAdvisorReview ¶
type URL ¶
type URL struct { Original string `json:"original"` Display string `json:"display"` Alternatives []string `json:"alternatives"` Canonical string `json:"canonical"` Mobile MobileURLItem `json:"mobile"` }
type UnitType ¶
type UnitType int8
UnitType controls the unit of measurement used in results.
Refer to Query Parameters for more detail.
type VideoData ¶
type VideoData struct { Duration *Duration `json:"duration"` Views VideoViews `json:"views"` Creator string `json:"creator"` Publisher string `json:"publisher"` Thumbnail *Thumbnail `json:"thumbnail"` }
type VideoResult ¶
type VideoSearchResult ¶
type VideoSearchResult struct { ResultContainer[VideoResult] Query *Query `json:"query"` }
type VideoViews ¶ added in v0.1.1
type VideoViews int
func (*VideoViews) UnmarshalJSON ¶ added in v0.1.1
func (v *VideoViews) UnmarshalJSON(in []byte) error
type WebSearchResult ¶
type WebSearchResult struct { Type string `json:"type"` Discussions *ResultContainer[DiscussionResult] `json:"discussions"` FAQ *ResultContainer[QA] `json:"faq"` InfoBox *ResultContainer[GraphInfoBox] `json:"infobox"` Locations *ResultContainer[LocationResult] `json:"locations"` Mixed *Mixed `json:"mixed"` News *ResultContainer[NewsResult] `json:"news"` Query *Query `json:"query"` Videos *ResultContainer[VideoResult] `json:"videos"` Web *ResultContainer[SearchResult] `json:"web"` Summarizer *Summarizer `json:"summarizer"` }