diff --git a/contrib/dendrite-demo-i2p/main.go b/contrib/dendrite-demo-i2p/main.go index c5aa7b761..92cfab49a 100644 --- a/contrib/dendrite-demo-i2p/main.go +++ b/contrib/dendrite-demo-i2p/main.go @@ -40,8 +40,10 @@ import ( "github.com/matrix-org/dendrite/userapi" ) -var samAddr = flag.String("samaddr", "127.0.0.1:7656", "Address to connect to the I2P SAMv3 API") -var _, skip = os.LookupEnv("CI") +var ( + samAddr = flag.String("samaddr", "127.0.0.1:7656", "Address to connect to the I2P SAMv3 API") + _, skip = os.LookupEnv("CI") +) func main() { cfg := setup.ParseFlags(true) diff --git a/contrib/dendrite-demo-i2p/main_i2p.go b/contrib/dendrite-demo-i2p/main_i2p.go index ff9622538..df55c4c62 100644 --- a/contrib/dendrite-demo-i2p/main_i2p.go +++ b/contrib/dendrite-demo-i2p/main_i2p.go @@ -65,8 +65,10 @@ func dialer() (*tor.Dialer, error) { return t.Dialer(context.TODO(), nil) } -var t, terr = start() -var tdialer, tderr = dialer() +var ( + t, terr = start() + tdialer, tderr = dialer() +) // Dial a network connection to an I2P server or a unix socket. Fail for clearnet addresses. func Dial(network, addr string) (net.Conn, error) { @@ -85,6 +87,12 @@ func Dial(network, addr string) (net.Conn, error) { if strings.HasSuffix(url.Host, ".i2p") { return sam.Dial(network, addr) } + if terr != nil { + return nil, terr + } + if (tderr != nil) || (tdialer == nil) { + return nil, tderr + } return tdialer.Dial(network, addr) } @@ -139,7 +147,7 @@ func SetupAndServeHTTPS( }, } - //Redirect for Landing Page + // Redirect for Landing Page externalRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, httputil.PublicStaticPath, http.StatusFound) }) diff --git a/contrib/dendrite-demo-i2p/main_test.go b/contrib/dendrite-demo-i2p/main_test.go index e9b5cab14..cc70ddba4 100644 --- a/contrib/dendrite-demo-i2p/main_test.go +++ b/contrib/dendrite-demo-i2p/main_test.go @@ -14,9 +14,7 @@ import ( // Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html // Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc func TestMain(t *testing.T) { - var ( - args []string - ) + var args []string for _, arg := range os.Args { switch { diff --git a/contrib/dendrite-demo-tor/main_test.go b/contrib/dendrite-demo-tor/main_test.go index e9b5cab14..cc70ddba4 100644 --- a/contrib/dendrite-demo-tor/main_test.go +++ b/contrib/dendrite-demo-tor/main_test.go @@ -14,9 +14,7 @@ import ( // Generate HTML with coverage: go tool cover -html=/somewhere/where/there/is/integrationcover.out -o cover.html // Source: https://dzone.com/articles/measuring-integration-test-coverage-rate-in-pouchc func TestMain(t *testing.T) { - var ( - args []string - ) + var args []string for _, arg := range os.Args { switch { diff --git a/contrib/dendrite-demo-tor/main_tor.go b/contrib/dendrite-demo-tor/main_tor.go index 922287053..d41059c07 100644 --- a/contrib/dendrite-demo-tor/main_tor.go +++ b/contrib/dendrite-demo-tor/main_tor.go @@ -54,8 +54,10 @@ func dialer() (*tor.Dialer, error) { return t.Dialer(context.TODO(), nil) } -var t, terr = start() -var tdialer, tderr = dialer() +var ( + t, terr = start() + tdialer, tderr = dialer() +) // Dial either a unix socket address, or connect to a remote address over Tor. Always uses Tor. func Dial(network, addr string) (net.Conn, error) { @@ -127,7 +129,7 @@ func SetupAndServeHTTPS( }, } - //Redirect for Landing Page + // Redirect for Landing Page externalRouter.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, httputil.PublicStaticPath, http.StatusFound) })