Skip to content

Instantly share code, notes, and snippets.

@zgramana
Created May 23, 2015 00:39
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 zgramana/aa188d067e10a91a5d39 to your computer and use it in GitHub Desktop.
Save zgramana/aa188d067e10a91a5d39 to your computer and use it in GitHub Desktop.
Gets the changes feed and prints the results.
package main
import "fmt"
import "io/ioutil"
import "net/http"
func main() {
// Changes Feed (GET http://127.0.0.1:4984/db/_changes?feed=longpoll&limit=50&heartbeat=300000&style=all_docs&since=1&include_docs=false)
// Create client
client := &http.Client{}
// Create request
req, err := http.NewRequest("GET", "http://127.0.0.1:4984/db/_changes?feed=longpoll&limit=50&heartbeat=300000&style=all_docs&since=1&include_docs=false", nil)
req.Header.Add("Accept-Encoding", `gzip/deflate`)
parseFormErr := req.ParseForm()
if parseFormErr != nil {
fmt.Println(parseFormErr)
}
// Fetch Request
resp, err := client.Do(req)
if err != nil {
fmt.Println("Failure : ", err)
}
// Read Response Body
respBody, _ := ioutil.ReadAll(resp.Body)
// Display Results
fmt.Println("response Status : ", resp.Status)
fmt.Println("response Headers : ", resp.Header)
fmt.Println("response Body : ", string(respBody))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment