A dialer which will reach clearnet, onion, and I2P sites, and an HTTP Client which has specific TLS behavior for Onion and I2P domains.
go get github.com/go-i2p/go-meta-dialer
package main
import (
"fmt"
"io/ioutil"
"net/http"
metadialer "github.com/go-i2p/go-meta-dialer"
)
func main() {
// IMPORTANT: Close the dialers when done to prevent SAM/Tor session leaks
defer metadialer.Garlic.Close()
defer metadialer.Onion.Close()
// Use the dialer directly
conn, err := metadialer.Dial("tcp", "example.i2p:80")
if err != nil {
panic(err)
}
defer conn.Close()
// Do something with the connection...
}
package main
import (
"fmt"
"io/ioutil"
metadialer "github.com/go-i2p/go-meta-dialer"
)
func main() {
// IMPORTANT: Close the dialers when done
defer metadialer.Garlic.Close()
defer metadialer.Onion.Close()
// Create a new HTTP client
client := metadialer.NewMetaHTTPClient(nil)
// Make requests to any network
resp, err := client.Get("https://example.com") // Normal website
// resp, err := client.Get("http://example.onion") // Tor onion service
// resp, err := client.Get("http://example.i2p") // I2P site
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}
// Set the MetaHTTPClient as the default for all HTTP requests
client := metadialer.NewMetaHTTPClient(nil)
http.DefaultClient = client.HTTPClient()
metadialer.ANON = true
: (Default) Routes all non-I2P connections through Tormetadialer.ANON = false
: Only routes .onion domains through Tor, direct connection for regular domains