goduckgo

package
v0.0.0-...-61f9a27 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2015 License: MIT Imports: 8 Imported by: 7

Documentation

Overview

Package goduckgo provides the functionality for using DuckDuckGo API. For the description of the API, visit http://duckduckgo.com/api.html.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(url string) ([]byte, error)

Do the HTTP requests against API and handle errors

func EncodeUrl

func EncodeUrl(query string) string

EncodeUrl given a text query

Types

type Icon

type Icon struct {
	URL    string
	Height interface{} // can be string or number ("16" or 16)
	Width  interface{} // can be string or number ("16" or 16)
}

Icon associated with related topics

URL: URL of icon
Height: height of icon (px)
Width: width of icon (px)

func (*Icon) IsEmpty

func (icon *Icon) IsEmpty() bool

IsEmpty if all Icon fields are empty

func (*Icon) Show

func (icon *Icon) Show(prefix string)

Show Show as standard output

type Message

type Message struct {
	Definition       string
	DefinitionSource string
	Heading          string
	AbstractText     string
	Abstract         string
	AbstractSource   string
	Image            string
	Type             string
	AnswerType       string
	Redirect         string
	DefinitionURL    string
	Answer           string
	AbstractURL      string
	Results          Results
	RelatedTopics    RelatedTopics
}

Message is a structure containing all the information returned by DDG for a query.

Abstract: topic summary (can contain HTML, e.g. italics)
AbstractText: topic summary (with no HTML)
AbstractSource: name of Abstract source
AbstractURL: deep link to expanded topic page in AbstractSource
Image: link to image that goes with Abstract
Heading: name of topic that goes with Abstract
Answer: instant answer
AnswerType: 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: dictionary definition (may differ from Abstract)
DefinitionSource: name of Definition source
DefinitionURL: deep link to expanded definition page in DefinitionSource
RelatedTopics: array of internal links to related topics associated with Abstract
Results: array of external links associated with Abstract
Type: response category, i.e. A (article), D (disambiguation), C (category), N (name), E (exclusive), or nothing.
Redirect: !bang redirect URL

func Query

func Query(query string) (*Message, error)

Query the API given a text query, returns a Message

func (*Message) Decode

func (message *Message) Decode(body []byte) error

Decode a message given a HTTP response body

type RelatedTopic

type RelatedTopic struct {
	Result   string
	Icon     Icon
	FirstURL string
	Text     string
}

RelatedTopic is a internal link to related topics associated with Abstract

	 Result: HTML link to a related topic
  FirstURL: first URL in Result
  Icon: icon associated with related topic
	 Text: text from first URL

func (*RelatedTopic) Show

func (topic *RelatedTopic) Show(prefix string)

Show RelatedTopic as standard output

type RelatedTopics

type RelatedTopics []RelatedTopic

type Result

type Result RelatedTopic

Result is an external link associated with Abstract

Result: HTML link(s) to external site(s)
FirstURL: first URL in Result
Icon: icon associated with FirstURL
Text: text from FirstURL

func (*Result) Show

func (result *Result) Show(prefix string)

Show Result as standard output

type Results

type Results []Result

Jump to

Keyboard shortcuts

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