googlecustomsearchapi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

googlecustomsearchapi

GitHub release (latest by date) GitHub tag (latest by date) Go Report Card

Google's custom search REST API client for Go

Example

func main() {
	httpc := http.DefaultClient

	gs := googlecustomsearchapi.New(httpc, "api-key-here", "engine-id-here")

	custom := map[string]string{
		`siteSearchFilter`: `i`,
		`siteSearch`:       `www.imdb.com`,
	}

	res, err := gs.Search(`the room`, 0, custom)
	if err != nil {
		panic(err)
	}

	for _, r := range res.Items {
		fmt.Printf(`%v %v`+"\n", r.Link, r.Title)
	}

}

Documentation

Index

Constants

View Source
const API_URL = "https://customsearch.googleapis.com/customsearch/v1"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client uses Google's custom search REST API See https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list

func New

func New(httpClient *http.Client, apikey string, engineid string) *Client

func (Client) Search

func (s Client) Search(query string, start uint, custom map[string]string) (Result, error)

Search searches Google's custom search REST API with given query

type Error

type Error struct {
	Error ErrorError `json:"error"`
}

type ErrorElement

type ErrorElement struct {
	Message string `json:"message"`
	Domain  string `json:"domain"`
	Reason  string `json:"reason"`
}

type ErrorError

type ErrorError struct {
	Code    int64          `json:"code"`
	Message string         `json:"message"`
	Errors  []ErrorElement `json:"errors"`
	Status  string         `json:"status"`
}

func (ErrorError) Error

func (e ErrorError) Error() string

type Item

type Item struct {
	//Kind             string `json:"kind"`
	Title       string `json:"title"`
	HTMLTitle   string `json:"htmlTitle"`
	Link        string `json:"link"`
	DisplayLink string `json:"displayLink"`
	Snippet     string `json:"snippet"`
	HTMLSnippet string `json:"htmlSnippet"`
	//CacheID          string `json:"cacheId"`
	FormattedURL     string `json:"formattedUrl"`
	HTMLFormattedURL string `json:"htmlFormattedUrl"`
}

type Queries

type Queries struct {
	Request  []RequestInfo `json:"request"`
	NextPage []RequestInfo `json:"nextPage"`
}

type RequestInfo

type RequestInfo struct {
	//Title                  string `json:"title"`
	TotalResults string `json:"totalResults"`
	//SearchTerms  string `json:"searchTerms"`
	Count      int64 `json:"count"`
	StartIndex int64 `json:"startIndex"`
	//Language               string `json:"language"`
	Safe                   string `json:"safe"`
	DisableCNTwTranslation string `json:"disableCnTwTranslation"`
	Hl                     string `json:"hl"`
}

type Result

type Result struct {
	//URL               URL               `json:"url"`
	Queries           Queries           `json:"queries"`
	SearchInformation SearchInformation `json:"searchInformation"`
	Items             []Item            `json:"items"`
}

type SearchInformation

type SearchInformation struct {
	SearchTime float64 `json:"searchTime"`
	//FormattedSearchTime   string  `json:"formattedSearchTime"`
	TotalResults string `json:"totalResults"`
}

type URL

type URL struct {
	Type     string `json:"type"`
	Template string `json:"template"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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