mirror of
https://github.com/go-i2p/goSam.git
synced 2025-06-16 12:05:47 -04:00
54 lines
969 B
Go
54 lines
969 B
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/eyedeekay/goSam"
|
|
)
|
|
|
|
func main() {
|
|
//In order to enable debugging, pass the SetDebug(true) option.
|
|
//sam, err := goSam.NewClientFromOptions(SetDebug(true))
|
|
|
|
// create a default sam client
|
|
sam, err := goSam.NewDefaultClient()
|
|
checkErr(err)
|
|
|
|
log.Println("Client Created")
|
|
|
|
// create a transport that uses SAM to dial TCP Connections
|
|
tr := &http.Transport{
|
|
Dial: sam.Dial,
|
|
}
|
|
|
|
// create a client using this transport
|
|
client := &http.Client{Transport: tr}
|
|
|
|
// send a get request
|
|
resp, err := client.Get("http://stats.i2p/")
|
|
checkErr(err)
|
|
defer resp.Body.Close()
|
|
|
|
log.Printf("Get returned %+v\n", resp)
|
|
|
|
// create a file for the response
|
|
file, err := os.Create("stats.html")
|
|
checkErr(err)
|
|
defer file.Close()
|
|
|
|
// copy the response to the file
|
|
_, err = io.Copy(file, resp.Body)
|
|
checkErr(err)
|
|
|
|
log.Println("Done.")
|
|
}
|
|
|
|
func checkErr(err error) {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|