-
-
Save groob/4c8fad93733f82d794d389476f2d717d to your computer and use it in GitHub Desktop.
Search my gists ;p
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 | |
import ( | |
"flag" | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
var ( | |
flQuery = flag.String("query", "", "which gist to look up") | |
) | |
flag.Parse() | |
if *flQuery == "" { | |
showGists() | |
return | |
} | |
searchGists(*flQuery) | |
} | |
func showGists() { | |
resp, err := http.Get("https://gist.github.com/search?q=%40pudquick&ref=searchresults") | |
if err != nil { | |
log.Fatal(err) | |
} | |
io.Copy(os.Stdout, resp.Body) | |
} | |
func searchGists(q string) { | |
resp, err := http.Get(fmt.Sprintf("https://gist.github.com/search?q=%%40pudquick+%s&ref=searchresults", q)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
io.Copy(os.Stdout, resp.Body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment