instant

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 39 Imported by: 2

Documentation

Overview

Package instant provides instant answers

Index

Constants

View Source
const ISO3166 = "ISO 3166-1 alpha-2"

ISO3166 is the ISO 3166-1 alpha-2 country code format

Variables

View Source
var ErrInvalidCurrency = fmt.Errorf("invalid currency")

ErrInvalidCurrency indicates the currency was invalid

View Source
var ErrInvalidURL = fmt.Errorf("unable to parse url")

ErrInvalidURL indicates an invalid url

View Source
var Nutrients = []Nutrient{
	{
		Name:  calcium,
		Code:  "301",
		Units: "mg",
	},
	{
		Name:  calories,
		Code:  "208",
		Units: "calories",
		Aliases: []nutrient{
			energy,
		},
	},
	{
		Name:  carbohydrates,
		Code:  "205",
		Units: "g",
		Aliases: []nutrient{
			carbs,
		},
	},
	{
		Name:  cholesterol,
		Code:  "601",
		Units: "mg",
	},
	{
		Name:  saturatedFat,
		Code:  "606",
		Units: "g",
	},
	{
		Name:  fat,
		Code:  "204",
		Units: "g",
	},
	{
		Name:  fiber,
		Code:  "291",
		Units: "g",
	},
	{
		Name:  iron,
		Code:  "303",
		Units: "mg",
	},
	{
		Name:  lipid,
		Code:  "204",
		Units: "g",
	},
	{
		Name:  magnesium,
		Code:  "304",
		Units: "mg",
	},
	{
		Name:  potassium,
		Code:  "306",
		Units: "mg",
	},
	{
		Name:  protein,
		Code:  "203",
		Units: "g",
	},
	{
		Name:  sodium,
		Code:  "307",
		Units: "mg",
	},
	{
		Name:  sugars,
		Code:  "269",
		Units: "g",
		Aliases: []nutrient{
			sugar,
		},
	},
	{
		Name:  vitaminA,
		Code:  "318",
		Units: "IU",
	},
	{
		Name:  vitaminB,
		Code:  "418",
		Units: "\u00b5g",
		Aliases: []nutrient{
			vitaminB12, vitaminBB12, vitaminBBB12,
		},
	},
	{
		Name:  vitaminC,
		Code:  "401",
		Units: "mg",
	},
	{
		Name:  vitaminD,
		Code:  "328",
		Units: "\u00b5g",
	},
	{
		Name:  zinc,
		Code:  "309",
		Units: "mg",
	},
}

Nutrients maps the USDA's codes with names and aliases

Functions

This section is empty.

Types

type Age

type Age struct {
	*Birthday `json:"birthday,omitempty"`
	*Death    `json:"death,omitempty"`
}

Age is a person's current age (in years) or age when they died

type Answer

type Answer struct {
	Data
	// contains filtered or unexported fields
}

Answer holds an instant answer when triggered

type Answerer

type Answerer interface {
	// contains filtered or unexported methods
}

Answerer outlines methods for an instant answer

type BirthStone

type BirthStone struct {
	Answer
}

BirthStone is an instant answer

type Birthday

type Birthday struct {
	Birthday wikipedia.DateTime `json:"birthday,omitempty"`
}

Birthday is a person's date of birth

type Breach

type Breach struct {
	Fetcher breach.Fetcher
	Answer
}

Breach is an instant answer

type Calculator

type Calculator struct {
	Answer
}

Calculator is an instant answer

type CamelCase

type CamelCase struct {
	Answer
}

CamelCase is an instant answer

type Characters

type Characters struct {
	Answer
}

Characters is an instant answer

type Clock

type Clock struct {
	Time     time.Time `json:"time"`
	Location struct {
		City    string `json:"city"`
		State   string `json:"state"`
		Country string `json:"country"`
	}
}

Clock is a current time for a location TODO: make Location a map/struct of different languages, not just 1

type Coin

type Coin struct {
	Answer
}

Coin is an instant answer

type Congress

type Congress struct {
	Fetcher congress.Fetcher
	Answer
}

Congress is an instant answer

type CountryCode

type CountryCode struct {
	Answer
}

CountryCode is an instant answer

type CountryCodeResponse

type CountryCodeResponse struct {
	Format   string
	Country  string
	Solution string
}

CountryCodeResponse is a response to the instant answer

type Currency

type Currency struct {
	FXFetcher     curr.FXFetcher
	CryptoFetcher curr.CryptoFetcher
	Answer
}

Currency is an instant answer

type CurrencyResponse

type CurrencyResponse struct {
	*curr.Response
	Notional         float64
	From             curr.Currency
	To               curr.Currency
	ForexCurrencies  []curr.Currency
	CryptoCurrencies []curr.Currency
	Currencies       []curr.Currency
}

CurrencyResponse is an instant answer response

type Data

type Data struct {
	Type      `json:"type,omitempty"`
	Triggered bool        `json:"triggered"`
	Solution  interface{} `json:"answer,omitempty"`
	Err       error       `json:"-"`
}

Data holds the returned data of an answer

type Death

type Death struct {
	Death wikipedia.DateTime `json:"death,omitempty"`
}

Death is a person's date of death TODO: add place of death, cause, etc.

type DigitalStorage

type DigitalStorage struct {
	Answer
}

DigitalStorage is an instant answer

type Discography

type Discography struct {
	disc.Fetcher
	Answer
}

Discography is an instant answer

type FedEx

type FedEx struct {
	parcel.Fetcher
	Answer
}

FedEx is an instant answer

type Frequency

type Frequency struct {
	Answer
}

Frequency is an instant answer

type GDP

type GDP struct {
	GDPFetcher ggdp.Fetcher
	Answer
}

GDP is an instant answer

type GDPResponse

type GDPResponse struct {
	Country string
	*ggdp.Response
}

GDPResponse is an instant answer response

type Hash

type Hash struct {
	Answer
}

Hash is an instant answer

type HashAlgo

type HashAlgo string

HashAlgo is a hashing algorithm

const (
	// MD5 is the md5 algorithm
	MD5 HashAlgo = "MD5"
	// SHA1 is the sha1 algorithm
	SHA1 HashAlgo = "SHA1"
	// SHA224 is the sha224 algorithm
	SHA224 HashAlgo = "SHA224"
	// SHA256 is the sha256 algorithm
	SHA256 HashAlgo = "SHA256"
	// SHA512 is the sha512 algorithm
	SHA512 HashAlgo = "SHA512"
)

type HashResponse

type HashResponse struct {
	Original string
	HashAlgo
	Solution string
}

HashResponse is the response to the instant answer

type Instant

type Instant struct {
	QueryVar           string
	BreachFetcher      breach.Fetcher
	CongressFetcher    congress.Fetcher
	DiscographyFetcher disc.Fetcher
	FedExFetcher       parcel.Fetcher
	Currency
	GDPFetcher           ggdp.Fetcher
	LinkShortener        shortener.Service
	LocationFetcher      location.Fetcher
	NutritionFetcher     nutrition.Fetcher
	PopulationFetcher    pop.Fetcher
	StackOverflowFetcher so.Fetcher
	StatusFetcher        status.Fetcher
	StockQuoteFetcher    stock.Fetcher
	TimeZoneFetcher      timezone.Fetcher
	UPSFetcher           parcel.Fetcher
	USPSFetcher          parcel.Fetcher
	WeatherFetcher       weather.Fetcher
	WHOISFetcher         whois.Fetcher
	WikipediaFetcher     wikipedia.Fetcher
}

Instant holds config information for the instant answers

func (*Instant) Solve

func (i *Instant) Solve(ia Answerer, r *http.Request) Data

Solve solves an instant answer

func (*Instant) Trigger

func (i *Instant) Trigger(ia Answerer, r *http.Request, lang language.Tag) bool

Trigger will trigger an instant answer

type Length

type Length struct {
	Answer
}

Length is an instant answer

type Map

type Map struct {
	location.Location
	Directions  bool
	Origin      string
	Destination string
}

Map is a instant answer response

type Maps

type Maps struct {
	LocationFetcher location.Fetcher
	Answer
}

Maps is an instant answer

type Minify

type Minify struct {
	Answer
}

Minify is an instant answer

type MortgageCalculator

type MortgageCalculator struct {
	Answer
}

MortgageCalculator is an instant answer

type Nutrient

type Nutrient struct {
	Name    nutrient
	Code    string
	Units   string
	Aliases []nutrient
}

Nutrient is an individual nutrient

type NutritionResponse

type NutritionResponse struct {
	Trigger   string
	Nutrients []Nutrient
	Response  *nutrition.Response
}

NutritionResponse is a food's nutrition content

type POTUS

type POTUS struct {
	Ordinal   string
	President Person
	Party     string
	Terms     int
	Vice      []Person
}

POTUS represents a single President & their Vice President(s)

type Person

type Person struct {
	Name  string
	Start string
	End   string
}

Person is a President or Vice President

type Population

type Population struct {
	PopulationFetcher pop.Fetcher
	Answer
}

Population is an instant answer

type PopulationResponse

type PopulationResponse struct {
	Country string
	*pop.Response
}

PopulationResponse is an instant answer response

type Potus

type Potus struct {
	Answer
}

Potus is an instant answer

type Power

type Power struct {
	Answer
}

Power is an instant answer

type Prime

type Prime struct {
	Answer
}

Prime is an instant answer

type Random

type Random struct {
	Answer
}

Random is an instant answer

type Reverse

type Reverse struct {
	Answer
}

Reverse is an instant answer

type SOAnswer

type SOAnswer struct {
	User string
	Text string
}

SOAnswer is the answer portion of a SO question

type Shortener

type Shortener struct {
	Service shortener.Service
	Answer
}

Shortener is an instant answer

type Speed

type Speed struct {
	Answer
}

Speed is an instant answer

type StackOverflow

type StackOverflow struct {
	so.Fetcher
	Answer
}

StackOverflow is an instant answer Alternative (but out-of-date): http://archive.org/download/stackexchange/

type StackOverflowAnswer

type StackOverflowAnswer struct {
	Question string
	Link     string
	Answer   SOAnswer
}

StackOverflowAnswer is a question and answer

type Stats

type Stats struct {
	Answer
}

Stats is an instant answer that returns the average, median, etc.

type Status

type Status struct {
	Fetcher status.Fetcher
	Answer
}

Status is an instant answer

type StockQuote

type StockQuote struct {
	Fetcher stock.Fetcher
	Answer
}

StockQuote is an instant answer

type Temperature

type Temperature struct {
	Answer
}

Temperature is an instant answer

type Triggerer

type Triggerer interface {
	Trigger()
}

Triggerer detects if the answer has been triggered

type Type

type Type string

Type is the answer type

const (
	WikipediaType         Type = "wikipedia"
	WikidataAgeType       Type = "wikidata age"
	WikidataBirthdayType  Type = "wikidata birthday"
	WikidataClockType     Type = "wikidata clock"
	WikidataDeathType     Type = "wikidata death"
	WikidataHeightType    Type = "wikidata height"
	WikidataNutritionType Type = "wikidata nutrition"
	WikidataWeightType    Type = "wikidata weight"
	WikiquoteType         Type = "wikiquote"
	WiktionaryType        Type = "wiktionary"
)

WikipediaType is a Wikipedia answer Type

const BirthStoneType Type = "birthstone"

BirthStoneType is an answer Type

const BreachType Type = "breach"

BreachType is an answer Type

const CalculatorType Type = "calculator"

CalculatorType is an answer Type

const CamelCaseType Type = "camelcase"

CamelCaseType is an answer Type

const CharactersType Type = "characters"

CharactersType is an answer Type

const CoinTossType Type = "coin toss"

CoinTossType is an answer Type

const CongressType Type = "congress"

CongressType is an answer Type

const CountryCodeType Type = "country code"

CountryCodeType is an answer Type

const CurrencyType Type = "currency"

CurrencyType is an answer Type

const DiscographyType Type = "discography"

DiscographyType is an answer Type

const FedExType Type = "fedex"

FedExType is an answer Type

const FrequencyType Type = "frequency"

FrequencyType is an answer Type

const GDPType Type = "gdp"

GDPType is an answer Type

const HashType Type = "hash"

HashType is an answer Type

const LocalWeatherType Type = "local weather"

LocalWeatherType is an answer Type

const MapsType Type = "maps"

MapsType is an answer Type

const MinifyType Type = "minify"

MinifyType is an answer Type

const MortageCalculatorType Type = "mortgage calculator"

MortageCalculatorType is an answer Type

const PopulationType Type = "population"

PopulationType is an answer Type

const PotusType Type = "potus"

PotusType is an answer Type

const PrimeType Type = "prime"

PrimeType is an answer Type

const RandomType Type = "random"

RandomType is an answer Type

const ReverseType Type = "reverse"

ReverseType is an answer Type

const StackOverflowType Type = "stackoverflow"

StackOverflowType is an answer Type

const StatsType Type = "stats"

StatsType is an answer Type

const StatusType Type = "status"

StatusType is an answer Type

const StockQuoteType Type = "stock quote"

StockQuoteType is an answer Type

const UPSType Type = "ups"

UPSType is an answer Type

const URLDecodeType Type = "urldecode"

URLDecodeType is an answer Type

const URLEncodeType Type = "urlencode"

URLEncodeType is an answer Type

const URLShortenerType Type = "url shortener"

URLShortenerType is an answer Type

const USPSType Type = "usps"

USPSType is an answer Type

const UnitConverterType Type = "unit converter"

UnitConverterType is an answer Type

const UserAgentType Type = "user agent"

UserAgentType is an answer Type

const WHOISType Type = "whois"

WHOISType is an answer Type

const WeatherType Type = "weather"

WeatherType is an answer Type

type UPS

type UPS struct {
	parcel.Fetcher
	Answer
}

UPS is an instant answer

type URLDecode

type URLDecode struct {
	Answer
}

URLDecode is an instant answer

type URLEncode

type URLEncode struct {
	Answer
}

URLEncode is an instant answer

type USPS

type USPS struct {
	parcel.Fetcher
	Answer
}

USPS is an instant answer

type UserAgent

type UserAgent struct {
	Answer
}

UserAgent is an instant answer

type WHOIS

type WHOIS struct {
	Answer
	whois.Fetcher
}

WHOIS is an instant answer

type Weather

type Weather struct {
	Fetcher         weather.Fetcher
	LocationFetcher location.Fetcher
	Answer
}

Weather is an instant answer

type Wikipedia

type Wikipedia struct {
	LocationFetcher  location.Fetcher
	NutritionFetcher nutrition.Fetcher
	TimeZoneFetcher  timezone.Fetcher
	wikipedia.Fetcher
	Answer
}

Wikipedia is a Wiki* instant answer, including Wikidata/Wikiquote/Wiktionary

Directories

Path Synopsis
Package breach checks for data breaches for a given account
Package breach checks for data breaches for a given account
Package congress retrieves members of the United States Congress
Package congress retrieves members of the United States Congress
Package currency fetches foreign exchange quotes
Package currency fetches foreign exchange quotes
Package discography fetches artist discography
Package discography fetches artist discography
gdp
Package gdp retrieves gdp data
Package gdp retrieves gdp data
population
Package population retrieves population data
Package population retrieves population data
Package location fetches geolocation data
Package location fetches geolocation data
Package nutrition provides food nutrition information
Package nutrition provides food nutrition information
Package parcel shows package status for UPS, Fedex and others
Package parcel shows package status for UPS, Fedex and others
Package shortener shortens urls
Package shortener shortens urls
Package stackoverflow fetches stackoverflow data
Package stackoverflow fetches stackoverflow data
Package status checks if a website is down
Package status checks if a website is down
Package stock fetches stock quote data
Package stock fetches stock quote data
Package timezone retrieves timezone info from lat/lon coordinates
Package timezone retrieves timezone info from lat/lon coordinates
Package weather fetches weather data
Package weather fetches weather data
Package whois fetchers WHOIS information for a domain
Package whois fetchers WHOIS information for a domain
Package wikipedia fetches Wikipedia articles Package wikipedia fetches Wikipedia articles
Package wikipedia fetches Wikipedia articles Package wikipedia fetches Wikipedia articles
cmd/dumper
Dumper downloads and dumps wikipedia/wikidata/wikiquotes data to a postgresql database.
Dumper downloads and dumps wikipedia/wikidata/wikiquotes data to a postgresql database.

Jump to

Keyboard shortcuts

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