/README.md
Markdown | 104 lines | 75 code | 29 blank | 0 comment | 0 complexity | 02012f6675cdd42a3d57fcef5f8c2843 MD5 | raw file
1goduckgo [](https://travis-ci.org/ajanicij/goduckgo)[](http://godoc.org/github.com/ajanicij/goduckgo/goduckgo) 2======== 3 4Go package for DuckDuckGo Instant Answer API. 5 6[DuckDuckGo](http://duckduckgo.com) is a search engine that: 7 8* Emphasizes privacy 9* Does not record user information 10* Breaks out of the filter bubble 11 12The Instant Answer API is described [here](http://duckduckgo.com/api.html). For 13example, the URL for querying about New York City is 14 15[http://api.duckduckgo.com/?q=New+York+City&format=json&pretty=1](http://api.duckduckgo.com/?q=New+York+City&format=json&pretty=1) 16 17The previous query causes DuckDuckGo to return the result in JSON format. 18 19Function goduckgo.Query declared as 20 21``` 22func Query(query string) (*Message, error) 23``` 24 25generates the URL, sends it to DuckDuckGo, receives the result, unmarshals from 26JSON format to Message structure and returns a pointer to the structure. 27 28Installation 29------------ 30 31``` 32go get -u github.com/ajanicij/goduckgo 33``` 34 35Usage 36----- 37 38Look at the source for the command-line utility, `main.go`. It imports 39package `github.com/ajanicij/goduckgo/goduckgo`, generates the query in the variable 40`query` (for example, "New York City") and passes it to function 41`goduckgo.Query`. That function returns two values: `*Message` and `error`. 42 43Command-line utility 44-------------------- 45 46The source code of the command-line utility is `main.go`. It builds `goduckgo` 47command. Its usage is: 48 49`goduckgo [{flags}] <query>` 50 51Flags determine which fields we will see in the result. 52For example, if we want to search for "New York City," we can issue command 53 54`goduckgo -All New York City` 55 56Flag -All tells the command that we want all fields. 57 58Command 59 60`goduckgo -help` 61 62(or `goduckgo` without any flags) will give us a help string that lists 63all available options: 64 65``` 66Usage of ./goduckgo: 67 -Abstract=false: Abstract 68 -AbstractSource=false: Abstract Source 69 -AbstractText=false: Abstract Text 70 -AbstractURL=false: Abstract URL 71 -All=false: All Fields 72 -Answer=false: Answer 73 -AnswerType=false: Answer Type 74 -Definition=false: Definition 75 -DefinitionSource=false: Definition Source 76 -DefinitionURL=false: Definition URL 77 -Heading=false: Heading 78 -Image=false: Image 79 -Redirect=false: Redirect 80 -RelatedTopics=false: Related Topics 81 -Results=false: Results 82 -Type=false: Type 83``` 84 85For example, query 86 87`goduckgo -Abstract DuckDuckgo` 88 89produces the following: 90 91``` 92Abstract: DuckDuckGo is an Internet search engine that emphasizes protecting searchers' 93privacy and avoiding the "filter bubble" of personalized search results. DuckDuckGo 94distinguishes itself from other search engines by not profiling its users and by deliberately 95showing all users the same search results for a given search term. DuckDuckGo also 96emphasizes getting information from the best sources rather than the most sources, 97generating its search results from key crowdsourced sites such as Wikipedia and from 98partnerships with other search engines like Yandex, Yahoo!, Bing, Wolfram Alpha and Yummly. 99``` 100 101License 102------- 103`goduckgo` is MIT licensed, see [here](https://github.com/ajanicij/goduckgo/blob/master/LICENSE). 104