Skip to content

Instantly share code, notes, and snippets.

@mattn
Created June 13, 2013 09:33
Show Gist options
  • Save mattn/5772450 to your computer and use it in GitHub Desktop.
Save mattn/5772450 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"encoding/json"
"log"
"net/http"
)
func main() {
r, err := http.Get("http://dev.redditanalytics.com/search/stream/")
if err != nil {
log.Fatal(err)
}
buf := bufio.NewReader(r.Body)
for {
line, _, err := buf.ReadLine()
if err != nil {
log.Println(err)
continue
}
var v interface{}
err = json.Unmarshal(line, &v)
if err != nil {
log.Println(err)
continue
}
author := v.(map[string]interface{})["author"].(string)
body := v.(map[string]interface{})["body"].(string)
log.Printf("%s: %s\n", author, body)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment