api

package module
v0.0.0-...-268be0e Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

README

Gofë Google Search API

Go Reference

This package provides an API to use Google Search without using Google Search.

Usage

package main

import (
	"fmt"

	"codeberg.org/ar324/gofe/api"
)

func main() {
	rs, err := api.Search("golang", 0)
	if err != nil {
		panic(err)
	}
	for _, v := range rs {
		fmt.Printf("URL: %s, Description: %s, Context: %s\n", v.URL, v.Desc, v.Context)
		// URL: https://go.dev/, Description: The Go Programming Language, Context: Connect Twitter GitHub Slack r/golang Meetup Golang Weekly. The Go Gopher. Copyright  Terms of Service  Privacy Policy  Report an Issue  Google logo. Downloads Get Started
		// . . .
	}

	sg, err := api.Suggest("golan")
	if err != nil {
		panic(err)
	}
	for _, v := range sg {
		fmt.Println(v)
		// golang
		// golan heights
		// golang tutorial
		// goland
		// golang playground
		// . . .
	}
}

Documentation

Index

Constants

View Source
const (

	// DefaultRegion is a two-letter country code that denotes the default region to pass to Google Search for location-aware results.
	DefaultRegion = "US"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	URL string
	// Desc is typically the <title> of the webpage.
	Desc string
	// Context holds text that shows why the URL is pertinent to the search query.
	Context string
}

Link represents a single search result.

type Result

type Result struct {
	Links []Link
	// RateLimited tells api's clients if Google has rate limited their requests.
	RateLimited bool
	// DYM holds the "Did you mean" suggestion, if returned by Google for a particular query.
	DYM string
	// SRF holds the "Showing results for" text, if returned by Google for a particular query.
	SRF string
}

Result holds a complete search result.

type SearchConfig

type SearchConfig struct {
	Region string
}

SearchConfig holds information pertaining to a search session.

func (SearchConfig) Search

func (sc SearchConfig) Search(sp SearchParameters) (Result, error)

Search queries Google Search returns a Result.

type SearchParameters

type SearchParameters struct {
	Query string
	Page  int
}

SearchParameters holds information pertaining to a search query. Note that Page is 0-indexed.

func (SearchParameters) Valid

func (sp SearchParameters) Valid() bool

Valid checks if a SearchParameters is valid.

type SugConfig

type SugConfig struct {
	Region string
}

SugConfig holds information pertaining to a suggestion session.

func (SugConfig) Suggest

func (sc SugConfig) Suggest(query string) (Suggestions, error)

Suggest suggests queries based on `query` and returns a `Suggestions`. There might be an error, so do check for it before using the returned `Suggestions`.

type Suggestions

type Suggestions []string

Suggestions is a slice of strings to store suggestions in.

Jump to

Keyboard shortcuts

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