Created
March 6, 2014 21:19
-
-
Save dgryski/9399888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package main is a command-line client search for godoc.org | |
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/url" | |
) | |
type Results struct { | |
Results []struct { | |
Path string | |
Synopsis string | |
} | |
} | |
func main() { | |
flag.Parse() | |
u := fmt.Sprintf("http://api.godoc.org/search?q=%s", url.QueryEscape(flag.Arg(0))) | |
r, err := http.Get(u) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer r.Body.Close() | |
var results Results | |
body, _ := ioutil.ReadAll(r.Body) | |
json.Unmarshal(body, &results) | |
for _, res := range results.Results { | |
fmt.Println(res.Path, ": ", res.Synopsis) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment