Skip to content

Instantly share code, notes, and snippets.

@rphillips
Created June 23, 2015 15:01
Show Gist options
  • Save rphillips/6a1094319114346bdfc0 to your computer and use it in GitHub Desktop.
Save rphillips/6a1094319114346bdfc0 to your computer and use it in GitHub Desktop.
package main
import(
"io/ioutil"
"fmt"
"net"
"net/http"
"log"
)
func fakeDial(proto, addr string) (conn net.Conn, err error) {
fmt.Println("using domain socket")
return net.Dial("unix", "/var/xapi/xapi")
}
func main() {
tr := &http.Transport{
Dial: fakeDial,
}
client := &http.Client{Transport: tr}
req, err := http.NewRequest("GET", "http://127.0.0.1/rrd_updates?start=1435024500&host=true&cf=AVERAGE", nil)
req.SetBasicAuth("root", "testing")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Print(string(body))
}
// GOOS=linux GOARCH=386 go build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment