Documentation
¶
Overview ¶
Package query provides functions to query web interfaces.
Index ¶
- func Bing(query string, conf *Config) (output string, err error)
- func GetShortURL(longURL string, conf *Config) (short string, err error)
- func GithubStars(userOrRepo string, conf *Config) (count int, err error)
- func Google(query string, conf *Config) (output string, err error)
- func WeatherYR(query string, conf *Config) (output string, err error)
- func Wolfram(query string, conf *Config) (output string, err error)
- func YouTube(msg string, cfg *Config) (output string, err error)
- type BingAnswer
- type BingError
- type Config
- type GoogleQueries
- type GoogleQuery
- type GoogleSearch
- type GoogleSearchInformation
- type GoogleSearchItem
- type Pod
- type URLShortenQuery
- type URLShortenResponse
- type WolframData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetShortURL ¶
GetShortURL takes a long url and returns a shorter url from the Google API
func GithubStars ¶
GithubStars takes a user (aarondl) or repo (aarondl/query) and returns the number of stars.
Types ¶
type BingAnswer ¶
type BingAnswer struct {
Type string `json:"_type"`
QueryContext struct {
OriginalQuery string `json:"originalQuery"`
} `json:"queryContext"`
WebPages struct {
WebSearchURL string `json:"webSearchUrl"`
TotalEstimatedMatches int `json:"totalEstimatedMatches"`
Value []struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
IsFamilyFriendly bool `json:"isFamilyFriendly"`
DisplayURL string `json:"displayUrl"`
Snippet string `json:"snippet"`
DateLastCrawled time.Time `json:"dateLastCrawled"`
SearchTags []struct {
Name string `json:"name"`
Content string `json:"content"`
} `json:"searchTags,omitempty"`
About []struct {
Name string `json:"name"`
} `json:"about,omitempty"`
} `json:"value"`
} `json:"webPages"`
Videos struct {
WebSearchURL string `json:"webSearchUrl"`
TotalEstimatedMatches int `json:"totalEstimatedMatches"`
Value []struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ContentURL string `json:"contentUrl"`
HostPageURL string `json:"hostPageUrl"`
Duration string `json:"duration"`
} `json:"value"`
} `json:"videos"`
RelatedSearches struct {
ID string `json:"id"`
Value []struct {
Text string `json:"text"`
DisplayText string `json:"displayText"`
WebSearchURL string `json:"webSearchUrl"`
} `json:"value"`
} `json:"relatedSearches"`
RankingResponse struct {
Mainline struct {
Items []struct {
AnswerType string `json:"answerType"`
ResultIndex int `json:"resultIndex"`
Value struct {
ID string `json:"id"`
} `json:"value"`
} `json:"items"`
} `json:"mainline"`
Sidebar struct {
Items []struct {
AnswerType string `json:"answerType"`
Value struct {
ID string `json:"id"`
} `json:"value"`
} `json:"items"`
} `json:"sidebar"`
} `json:"rankingResponse"`
}
This struct formats the answers provided by the Bing Web Search API.
type Config ¶
type Config struct {
BingAPIKey string `toml:"bing_api_key"`
GeonamesID string `toml:"geonames_id"`
GithubAPIKey string `toml:"github_api_key"`
GoogleURLAPIKey string `toml:"google_url_api_key"`
GoogleSearchAPIKey string `toml:"google_search_api_key"`
GoogleSearchCXID string `toml:"google_search_cx_id"`
GoogleYoutubeKey string `toml:"google_youtube_key"`
WolframID string `toml:"wolfram_id"`
}
Config is the configuration for this thing.
type GoogleQueries ¶
type GoogleQueries struct {
NextPage []GoogleQuery `json:"nextPage"`
Request []GoogleQuery `json:"request"`
}
GoogleQueries a set of queries involved in the current search query
type GoogleQuery ¶
type GoogleQuery struct {
CX string `json:"cx"`
Title string `json:"title"`
TotalResults string `json:"totalResults"`
SearchTerms string `json:"searchTerms"`
Count int `json:"count"`
StartIndex int `json:"startIndex"`
InputEncoding string `json:"inputEncoding"`
OutputEncoding string `json:"outputEncoding"`
Safe string `json:"safe"`
}
GoogleQuery is a description of a search query
type GoogleSearch ¶
type GoogleSearch struct {
Items []GoogleSearchItem `json:"items"`
Info GoogleSearchInformation `json:"searchInformation"`
Queries GoogleQueries `json:"queries"`
}
GoogleSearch is used to parse the response from Google.
type GoogleSearchInformation ¶
type GoogleSearchInformation struct {
TotalResults string `json:"totalResults"`
SearchTime float64 `json:"searchTime"`
FormattedTotalResults string `json:"formattedTotalResults"`
FormattedSearchTime string `json:"formattedSearchTime"`
}
GoogleSearchInformation is meta about the search
type GoogleSearchItem ¶
type GoogleSearchItem struct {
Title string `json:"title"`
Snippet string `json:"snippet"`
Link string `json:"link"`
DisplayLink string `json:"displayLink"`
FormattedURL string `json:"formattedUrl"`
HTMLTitle string `json:"htmlTitle"`
HTMLSnippet string `json:"htmlSnippet"`
HTMLFormattedURL string `json:"htmlFormattedUrl"`
CacheID string `json:"cacheId"`
Kind string `json:"kind"`
}
GoogleSearchItem is a search result item from a google search
type Pod ¶
type Pod struct {
Title string `xml:"title,attr"`
ID string `xml:"id,attr"`
Primary bool `xml:"primary,attr"`
Numsubpods int `xml:"numsubpods,attr"`
PlainTexts []string `xml:"subpod>plaintext"`
}
Pod is a substruct of WolframData.
type URLShortenQuery ¶
type URLShortenQuery struct {
LongURL string `json:"longUrl"`
}
URLShortenQuery is the json request to the server
type URLShortenResponse ¶
URLShortenResponse is the json response back from the server
type WolframData ¶
type WolframData struct {
XMLName xml.Name `xml:"queryresult"`
Success bool `xml:"success,attr"`
ParseTiming float64 `xml:"parsetiming,attr"`
Numpods int `xml:"numpods,attr"`
Pods []*Pod `xml:"pod"`
DidYouMeans []string `xml:"didyoumeans>didyoumean"`
}
WolframData is used to parse the response from WolframAlpha.