brave

package module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 11 Imported by: 0

README

Brave Search API for Go

Go Reference

A Go client for the Brave Search API.

Install

$ go get dev.freespoke.com/brave-search

Usage

client, err := New(key)
if err != nil {
    log.Fatal(err)
}

res, err := client.WebSearch(context.Background(), "freespoke")
if err != nil {
    log.Fatal(err)
}

Documentation

Status

The client works, but is poorly tested. Some features and types are not available. The documentation is unclear, and in certain places it seems that the API was rushed out to take advantage of the opportunity to capture businesses fleeing from Bing. That's not to say it's a bad API, just that there's a bit of weirdness that I try to paper over, and that the documentation seems to miss certain things, and that certain types don't seem to be returned as I'd expect.

I'll try to keep this up-to-date and adopt new stuff as it becomes available.

License

MIT (See LICENSE.md).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	Text          string `json:"text"`
	Author        string `json:"author"`
	UpvoteCount   int    `json:"upvoteCount"`
	DownvoteCount int    `json:"downvoteCount"`
}

type Article

type Article struct {
	Author              []Person      `json:"author"`
	Date                string        `json:"date"`
	Publisher           *Organization `json:"organization"`
	Thumbnail           *Thumbnail    `json:"thumbnail"`
	IsAccessibleForFree bool          `json:"isAccessibleForFree"`
}

type Book

type Book struct {
	Title     string   `json:"title"`
	Author    []Person `json:"author"`
	Date      string   `json:"date"`
	Price     *Price   `json:"price"`
	Pages     Number   `json:"pages"`
	Publisher *Person  `json:"publisher"`
	Rating    *Rating  `json:"rating"`
}

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)
}

Brave is an interface for fetching results from the Brave Search API.

func New

func New(subscriptionToken string, options ...ClientOption) (Brave, error)

type ButtonResult

type ButtonResult struct {
	Type  string `json:"type"`
	Title string `json:"title"`
	URL   string `json:"url"`
}

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 Contact

type Contact struct {
	Email     string `json:"email"`
	Telephone string `json:"telephone"`
}

type CreativeWork

type CreativeWork struct {
	Name      string     `json:"name"`
	Thumbnail *Thumbnail `json:"thumbnail"`
	Rating    *Rating    `json:"rating"`
}

type DataProvider

type DataProvider struct {
	Type     string `json:"type"`
	Name     string `json:"name"`
	URL      string `json:"url"`
	LongName string `json:"long_name"`
	Image    string `json:"img"`
}

type DayOpeningHours

type DayOpeningHours struct {
	AbbrName string `json:"abbr_name"`
	FullName string `json:"full_name"`
	Opens    string `json:"opens"`
	Closes   string `json:"closes"`
}

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

type Duration time.Duration

func (*Duration) Duration

func (d *Duration) Duration() *time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(in []byte) error

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"`
}

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"`
	Time   *Timestamp `json:"-"`
}

func (ErrorResponse) Error

func (er ErrorResponse) Error() string

type FAQ

type FAQ struct {
	Type    string `json:"type"`
	Results []QA   `json:"results"`
}

type ForumData

type ForumData struct {
	ForumName  string `json:"forum_name"`
	NumAnswers int    `json:"num_answers"`
	Score      string `json:"score"`
	Question   string `json:"question"`
	TopComment string `json:"top_comment"`
}

type Freshness

type Freshness int8

Freshness filters search results by when they were discovered.

Refer to Query Parameters for more detail.

const (
	FreshnessNone Freshness = iota
	FreshnessPastDay
	FreshnessPastWeek
	FreshnessPastMonth
	FreshnessPastYear
)

func (Freshness) String

func (f Freshness) String() string

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"`
}

type ImageProperties

type ImageProperties struct {
	URL         string `json:"url"`
	Resized     string `json:"resized"`
	Height      int    `json:"height"`
	Width       int    `json:"width"`
	Format      string `json:"format"`
	ContentSize string `json:"content_size"`
	Placeholder string `json:"placeholder"`
}

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 KnowledgeGraphEntity struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         *URL   `json:"url"`
	Thumbnail   *URL   `json:"thumbnail"`
}

type KnowledgeGraphProfile

type KnowledgeGraphProfile struct {
	KnowledgeGraphEntity

	URL         string `json:"url"`
	Description string `json:"description"`
}

type Language

type Language struct {
	Main string `json:"main"`
}

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"`
}

type Locations

type Locations struct {
	Type    string           `json:"type"`
	Results []LocationResult `json:"results"`
}

type MetaURL

type MetaURL struct {
	Scheme   string `json:"scheme"`
	NetLoc   string `json:"netloc"`
	Hostname string `json:"hostname"`
	Favicon  string `json:"favicon"`
	Path     string `json:"path"`
}

type Mixed

type Mixed struct {
	Type string `json:"type"`
	Main []ResultReference
	Top  []ResultReference
	Side []ResultReference
}

type MobileURLItem

type MobileURLItem struct {
	Original string `json:"original"`
	AMP      string `json:"amp"`
	Android  string `json:"android"`
	IOS      string `json:"ios"`
}

type MovieData

type MovieData struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	URL         string     `json:"url"`
	Thumbnail   *Thumbnail `json:"thumbnail"`
	Release     string     `json:"release"`
	Directors   []Person   `json:"directors"`
	Actors      []Person   `json:"actors"`
	Rating      *Rating    `json:"rating"`
}

type MusicRecording

type MusicRecording struct {
	Name      string     `json:"name"`
	Thumbnail *Thumbnail `json:"thumbnail"`
	Rating    *Rating    `json:"rating"`
}

type NewsResult

type NewsResult struct {
	Result
	MetaURL   MetaURL    `json:"meta_url"`
	Source    string     `json:"source"`
	Breaking  bool       `json:"breaking"`
	Thumbnail *Thumbnail `json:"thumbnail"`
	Age       *Timestamp `json:"age"`
}

type Number added in v0.1.2

type Number int

func (*Number) UnmarshalJSON added in v0.1.2

func (n *Number) UnmarshalJSON(b []byte) error

type OpeningHours

type OpeningHours struct {
	CurrentDay []DayOpeningHours   `json:"current_day"`
	Days       [][]DayOpeningHours `json:"days"`
}

type Organization

type Organization struct {
	Person

	Type string `json:"type"`
}

type Person

type Person struct {
	Type      string     `json:"type"`
	Name      string     `json:"name"`
	URL       string     `json:"url"`
	Thumbnail *Thumbnail `json:"thumbnail"`
}

type PictureResults

type PictureResults struct {
	Results     []Thumbnail `json:"results"`
	ViewMoreURL string      `json:"viewMoreUrl"`
}

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 Price

type Price struct {
	Price         string `json:"price"`
	PriceCurrency string `json:"price_currency"`
}

type Profile

type Profile struct {
	Name     string `json:"name"`
	LongName string `json:"long_name"`
	URL      string `json:"url"`
	Image    string `json:"img"`
}

type QA

type QA struct {
	Question string  `json:"question"`
	Answer   string  `json:"answer"`
	Title    string  `json:"title"`
	URL      string  `json:"url"`
	MetaURL  MetaURL `json:"meta_url"`
}

type QAPage

type QAPage struct {
	Question string  `json:"question"`
	Answer   *Answer `json:"answer"`
}

type Query

type Query struct {
	Original             string    `json:"original"`
	ShowStrictWarning    bool      `json:"show_strict_warning"`
	Altered              string    `json:"altered"`
	Safesearch           bool      `json:"safesearch"`
	IsNavigational       bool      `json:"is_navigational"`
	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"`
}

type Rating

type Rating struct {
	RatingValue   float32  `json:"ratingValue"`
	BestRating    float32  `json:"bestRating"`
	ReviewCount   int      `json:"reviewCount"`
	Profile       *Profile `json:"profile"`
	IsTripadvisor bool     `json:"is_tripadvisor"`
}

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 ResultContainer[T any] struct {
	Type             string `json:"type"`
	Results          []T    `json:"results"`
	MutatedByGoggles bool   `json:"mutated_by_goggles"`
}

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 ResultReference struct {
	Type  string `json:"type"`
	Index int    `json:"index"`
	All   bool   `json:"all"`
}

type Review

type Review struct {
	Type        string     `json:"type"`
	Name        string     `json:"name"`
	Thumbnail   *Thumbnail `json:"thumbnail"`
	Description string     `json:"description"`
	Rating      *Rating    `json:"rating"`
}

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 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 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

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"`
	Subtype     string          `json:"subtype"`
	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"`
	Restaurant  *LocationResult `json:"restaurant"`
	Locations   *Locations      `json:"locations"`
	Video       *VideoData      `json:"video"`
	Movie       *MovieData      `json:"movie"`
	FAQ         *FAQ            `json:"faq"`
	QA          *QAPage         `json:"qa"`
	Book        *Book           `json:"book"`
	Rating      *Rating         `json:"rating"`
	Article     *Article        `json:"article"`
	// Product     any             `json:"product"`
	// ProductCluster []any `json:"product_cluster"`
	ClusterType    string          `json:"cluster_type"`
	Cluster        []Result        `json:"cluster"`
	CreativeWork   *CreativeWork   `json:"creative_work"`
	MusicRecording *MusicRecording `json:"music_recording"`
	Review         *Review         `json:"review"`
	Software       *Software       `json:"software"`
	ContentType    string          `json:"content_type"`
}

type Software

type Software struct {
	Name           string `json:"name"`
	Author         string `json:"author"`
	Version        string `json:"version"`
	CodeRepository string `json:"codeRepository"`
	Homepage       string `json:"homepage"`
	DatePublished  string `json:"datePublisher"`
	IsNPM          bool   `json:"is_npm"`
	IsPyPi         bool   `json:"is_pypi"`
}

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 SuggestResult struct {
	Query       string `json:"string"`
	IsEntity    bool   `json:"is_entity"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Image       string `json:"img"`
}

type SuggestSearchResult

type SuggestSearchResult struct {
	Type    string          `json:"type"`
	Query   *Query          `json:"query"`
	Results []SuggestResult `json:"results"`
}

type Thumbnail

type Thumbnail struct {
	Src             string `json:"src"`
	Height          int    `json:"height"`
	Width           int    `json:"width"`
	BackgroundColor string `json:"bg_color"`
	Original        string `json:"original"`
	Duplicated      bool   `json:"duplicated"`
	Theme           string `json:"theme"`
}

type Timestamp

type Timestamp time.Time

func (*Timestamp) Time

func (t *Timestamp) Time() *time.Time

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(in []byte) (err error)

type TripAdvisorReview

type TripAdvisorReview struct {
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Date        string  `json:"date"`
	Rating      *Rating `json:"rating"`
	Author      *Person `json:"author"`
	ReviewURL   string  `json:"review_url"`
	Language    string  `json:"language"`
}

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 Unit

type Unit struct {
	Value float32 `json:"value"`
	Units string  `json:"units"`
}

type UnitType

type UnitType int8

UnitType controls the unit of measurement used in results.

Refer to Query Parameters for more detail.

const (
	UnitTypeNone UnitType = iota
	UnitTypeMetric
	UnitTypeImperial
)

func (UnitType) String

func (u UnitType) String() string

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 VideoResult struct {
	Result
	Type      string     `json:"type"`
	Data      *VideoData `json:"video"`
	MetaURL   MetaURL    `json:"meta_url"`
	Thumbnail *Thumbnail `json:"thumbnail"`
	Age       *Timestamp `json:"age"`
}

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         any                                `json:"faq"`
	InfoBox     *ResultContainer[GraphInfoBox]     `json:"infobox"`
	Locations   *Locations                         `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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL