Documentation
¶
Overview ¶
Package ddgs is a Go port of the Python "ddgs" library (https://github.com/deedy5/ddgs) — DDGS | Dux Distributed Global Search. A metasearch library that aggregates results from diverse web search services.
Index ¶
- Constants
- Variables
- type Config
- type DDGS
- func (d *DDGS) Books(ctx context.Context, query string, opts *SearchOptions) ([]Result, error)
- func (d *DDGS) Extract(ctx context.Context, rawURL string, format ExtractFormat) (*Extracted, error)
- func (d *DDGS) Images(ctx context.Context, query string, opts *SearchOptions) ([]Result, error)
- func (d *DDGS) News(ctx context.Context, query string, opts *SearchOptions) ([]Result, error)
- func (d *DDGS) Text(ctx context.Context, query string, opts *SearchOptions) ([]Result, error)
- func (d *DDGS) Videos(ctx context.Context, query string, opts *SearchOptions) ([]Result, error)
- type ExtractFormat
- type Extracted
- type Result
- type SearchOptions
- type Verify
Constants ¶
const DefaultMaxResults = 10
DefaultMaxResults mirrors the Python default max_results=10.
Variables ¶
var ErrDDGS = errors.New("ddgs")
ErrDDGS is the base error for the ddgs package. All errors returned by this package wrap ErrDDGS.
var ErrNoResults = errors.New("ddgs: no results found")
ErrNoResults is returned when no engine produced any results.
var ErrRatelimit = errors.New("ddgs: ratelimit")
ErrRatelimit is returned for rate limit exceeded errors during requests.
var ErrTimeout = errors.New("ddgs: timeout")
ErrTimeout is returned for timeout errors during requests.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Proxy for the HTTP clients; supports http/https/socks5 URLs.
// The alias "tb" expands to the Tor Browser proxy. Falls back to the
// DDGS_PROXY environment variable when empty.
Proxy string
// Timeout per engine request. Defaults to 5s (Python default timeout=5).
Timeout time.Duration
// Verify controls TLS verification.
Verify Verify
// Threads caps the number of concurrent engine requests per search.
// Zero means automatic (based on max_results), mirroring DDGS.threads.
Threads int
}
Config configures a DDGS instance, mirroring DDGS.__init__ kwargs.
type DDGS ¶
type DDGS struct {
// contains filtered or unexported fields
}
DDGS | Dux Distributed Global Search. A metasearch client that aggregates results from diverse web search services.
d, err := ddgs.New(nil) results, err := d.Text(ctx, "python", nil)
DDGS is safe for concurrent use: the engine cache is mutex-protected and engines only mutate goroutine-safe state (net/http cookie jars) after construction.
func New ¶
New creates a DDGS instance. A nil config uses defaults (no proxy — or DDGS_PROXY env var, 5s timeout, TLS verification on).
func (*DDGS) Extract ¶
func (d *DDGS) Extract(ctx context.Context, rawURL string, format ExtractFormat) (*Extracted, error)
Extract fetches a URL and extracts its content. Mirrors DDGS.extract().
type ExtractFormat ¶
type ExtractFormat string
ExtractFormat selects the output format of Extract, mirroring the Python `fmt` parameter values.
const ( // FormatTextMarkdown converts the page to Markdown-ish plain text (default). FormatTextMarkdown ExtractFormat = "text_markdown" // FormatTextPlain converts the page to plain text. FormatTextPlain ExtractFormat = "text_plain" // FormatText returns the raw HTML text. FormatText ExtractFormat = "text" // FormatContent returns the raw response bytes. FormatContent ExtractFormat = "content" )
type Extracted ¶
type Extracted struct {
URL string
Content string // textual formats
Bytes []byte // FormatContent
}
Extracted is the return value of Extract, mirroring the Python {"url": ..., "content": ...} dict.
type Result ¶
Result is a single search result. It mirrors the dicts returned by the Python ddgs library: keys and value shapes are identical per category.
text: title, href, body
images: title, image, thumbnail, url, height, width, source
news: date, title, body, url, image, source
videos: title, content, description, duration, embed_html, embed_url,
image_token, images, provider, published, publisher, statistics, uploader
books: title, author, publisher, info, url, thumbnail
type SearchOptions ¶
type SearchOptions struct {
// Region, e.g. "us-en", "uk-en", "ru-ru". Default "us-en".
Region string
// SafeSearch: "on", "moderate", "off". Default "moderate".
SafeSearch string
// TimeLimit: "d", "w", "m", "y". Default none.
TimeLimit string
// MaxResults is the maximum number of results to return. Default 10.
// Set to -1 to return everything found (Python max_results=None).
MaxResults int
// Page of results, 1-based. Default 1.
Page int
// Backend is a single or comma-delimited list of backends, or
// "auto"/"all". Default "auto".
Backend string
// Extra engine-specific parameters, mirroring Python **kwargs
// (e.g. images: size, color, type_image, layout, license_image;
// videos: resolution, duration, license_videos).
Extra map[string]string
}
SearchOptions are the per-search keyword arguments, mirroring DDGS._search_sync kwargs. The zero value gives Python's defaults.
type Verify ¶
type Verify struct {
// SkipVerify disables TLS certificate verification (Python verify=False).
SkipVerify bool
// CACertFile is a path to a PEM file with custom CA certs (Python verify="path").
CACertFile string
}
Verify controls TLS verification, mirroring the Python `verify: bool | str` parameter (True / False / path-to-PEM).