Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created April 2, 2012 05:34
Show Gist options
  • Save jordanorelli/2281035 to your computer and use it in GitHub Desktop.
Save jordanorelli/2281035 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
)
var statusUrl, _ = url.Parse("https://stream.twitter.com/1/statuses/sample.json")
// var statusUrl, _ = url.Parse("https://userstream.twitter.com/2/user.json")
func main() {
c := new(http.Client)
req, err := http.NewRequest("GET", statusUrl.String(), nil)
if err != nil {
panic(err)
}
req.SetBasicAuth("s", "")
res, err := c.Do(req)
if err != nil {
panic(err)
}
if res.StatusCode < 200 || res.StatusCode >= 300 {
fmt.Println(res)
os.Exit(1)
}
reader := bufio.NewReader(res.Body)
for {
raw, _ := reader.ReadBytes('\r')
var prettyBuf bytes.Buffer
json.Indent(&prettyBuf, raw, "", " ")
prettyBuf.WriteTo(os.Stdout)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment