Documentation
¶
Overview ¶
DuckDuckGo Zero-click API client. See https://duckduckgo.com/api.html for information about the API.
Example command-line program to show abstracts:
package main
import (
"fmt"
"github.com/whee/ddg"
"os"
)
func main() {
for _, s := range os.Args[1:] {
if r, err := ddg.ZeroClick(s); err == nil {
fmt.Printf("%s: %s\n", s, r.Abstract)
} else {
fmt.Printf("Error looking up %s: %v\n", s, err)
}
}
}
Index ¶
Constants ¶
const ( Article = "A" Disambiguation = "D" Category = "C" Name = "N" Exclusive = "E" None = "" )
const ( DDG_API_BASE_URL = "api.duckduckgo.com" DDG_API_URL = "http://api.duckduckgo.com/?q=%s&format=json" DDG_API_URL_SECURE = "https://api.duckduckgo.com/?q=%s&format=json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CategoryType ¶
type CategoryType string
type Client ¶
type Client struct {
// Secure specifies whether HTTPS is used.
Secure bool
// NoHtml will remove HTML from the response text
NoHtml bool `parameter:"no_html"`
// SkipDisambiguation will prevent Disambiguation type responses
SkipDisambiguation bool `parameter:"skip_disambig"`
// NoRedirect skips HTTP redirects (for !bang commands)
NoRedirect bool `parameter:"no_redirect"`
// BaseURL specifies where to send API requests. If zero-value,
// "api.duckduckgo.com" is used.
BaseURL string
}
A Client is a DDG Zero-click client.
type Icon ¶
type Icon struct {
URL string // URL of icon
Height int `json:"-"` // height of icon (px)
Width int `json:"-"` // width of icon (px)
// The height and width can be "" (string; we treat as 0) or an int. Unmarshal here, then populate the above two.
RawHeight interface{} `json:"Height"`
RawWidth interface{} `json:"Width"`
}
type Response ¶
type Response struct {
Abstract string // topic summary (can contain HTML, e.g. italics)
AbstractText string // topic summary (with no HTML)
AbstractSource string // name of Abstract source
AbstractURL string // deep link to expanded topic page in AbstractSource
Image string // link to image that goes with Abstract
Heading string // name of topic that goes with Abstract
Answer string // instant answer
AnswerType string // type of Answer, e.g. calc, color, digest, info, ip, iploc, phone, pw, rand, regexp, unicode, upc, or zip (see goodies & tech pages for examples).
Definition string // dictionary definition (may differ from Abstract)
DefinitionSource string // name of Definition source
DefinitionURL string // deep link to expanded definition page in DefinitionSource
RelatedTopics []Result // array of internal links to related topics associated with Abstract
RelatedTopicsSections []SectionResults // disambiguation types will populate this
Results []Result // array of external links associated with Abstract
Type CategoryType // response category, i.e. A (article), D (disambiguation), C (category), N (name), E (exclusive), or nothing.
Redirect string // !bang redirect URL
}
Response represents the response from a zero-click API request via the ZeroClick function.
type SectionResults ¶
SectionResults are results grouped by a topic name.