1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-02-04 18:21:53 +02:00

55 lines
1.1 KiB
Go
Raw Normal View History

2021-11-01 11:00:21 +00:00
package google
import (
"go.m3o.com/client"
)
2021-12-30 08:44:34 +00:00
type Google interface {
Search(*SearchRequest) (*SearchResponse, error)
}
2021-11-01 11:00:21 +00:00
func NewGoogleService(token string) *GoogleService {
return &GoogleService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type GoogleService struct {
client *client.Client
}
// Search for videos on Google
func (t *GoogleService) Search(request *SearchRequest) (*SearchResponse, error) {
2021-12-21 13:18:29 +00:00
2021-11-01 11:00:21 +00:00
rsp := &SearchResponse{}
return rsp, t.client.Call("google", "Search", request, rsp)
2021-12-21 13:18:29 +00:00
2021-11-01 11:00:21 +00:00
}
type SearchRequest struct {
// Query to search for
Query string `json:"query"`
}
type SearchResponse struct {
// List of results for the query
Results []SearchResult `json:"results"`
}
type SearchResult struct {
// abridged version of this search result’s URL, e.g. www.exampe.com
2021-12-21 13:18:29 +00:00
DisplayUrl string `json:"display_url"`
2021-11-01 11:00:21 +00:00
// id of the result
Id string `json:"id"`
// kind of result; "search"
Kind string `json:"kind"`
// the result snippet
Snippet string `json:"snippet"`
// title of the result
Title string `json:"title"`
// the full url for the result
Url string `json:"url"`
}