cse

package module
v0.0.0-...-2f22219 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 8 Imported by: 0

README

google cse for golang

cse.google.com api for golang

google 自定义搜索

Example

package main

import cse "github.com/tiancheng91/google-cse"

func main() {
    agent := cse.New("008063188944472181627:xqha3yefaee", "zh_CN")

    # 参数: 查询词, 页数, 页大小
    result = agent.Search("123456", 1, 20)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent is return

func New

func New(cx string, lang string) (agent Agent)

New return a search instance

func (*Agent) Query

func (a *Agent) Query(q string, page int64, pageSize int64) (ret *SearchRet, err error)

Query is do search and return ret list

type Context

type Context struct {
	Title        string        `json:"title"`
	TotalResults string        `json:"total_results"`
	Facets       []interface{} `json:"facets"`
}

type Cursor

type Cursor struct {
	CurrentPageIndex     int64  `json:"currentPageIndex"`
	EstimatedResultCount string `json:"estimatedResultCount"`
	MoreResultsURL       string `json:"moreResultsUrl"`
	ResultCount          string `json:"resultCount"`
	SearchResultTime     string `json:"searchResultTime"`
	Pages                []Page `json:"pages"`
}

type Page

type Page struct {
	Label int64  `json:"label"`
	Start string `json:"start"`
}

type Request

type Request struct {
	Start int64 `json:"start" url:"start"`
	Num   int64 `json:"num" url:"num"`

	Hl     string `json:"hl" url:"hl"`
	Key    string `json:"key" url:"key"`
	Cx     string `json:"cx" url:"cx"`
	CSETok string `json:"cse_tok" url:"cse_tok"`
	Q      string `json:"q" url:"q"`
}

Request is cse api query params

type Result

type Result struct {
	GsearchResultClass  string `json:"GsearchResultClass"`
	CacheURL            string `json:"cacheUrl"`
	ClicktrackURL       string `json:"clicktrackUrl"`
	Content             string `json:"content"`
	ContentNoFormatting string `json:"contentNoFormatting"`
	FormattedURL        string `json:"formattedUrl"`
	Title               string `json:"title"`
	TitleNoFormatting   string `json:"titleNoFormatting"`
	UnescapedURL        string `json:"unescapedUrl"`
	URL                 string `json:"url"`
	VisibleURL          string `json:"visibleUrl"`
}

type SearchRet

type SearchRet struct {
	Cursor  Cursor   `json:"cursor"`
	Context Context  `json:"context"`
	Results []Result `json:"results"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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