Skip to content

Instantly share code, notes, and snippets.

@dgryski
Created March 6, 2014 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgryski/9399888 to your computer and use it in GitHub Desktop.
Save dgryski/9399888 to your computer and use it in GitHub Desktop.
// 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