From ffe60bae85fd9f0af27832e987118035b68b79f8 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Tue, 8 Feb 2022 19:00:37 +0400 Subject: [PATCH] Host can have :port attached, so it is better to check if string contains rather ends with a particular TLD. --- pkg/utils/dwelling.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/utils/dwelling.go b/pkg/utils/dwelling.go index 5a9f6f6..6a8fc84 100644 --- a/pkg/utils/dwelling.go +++ b/pkg/utils/dwelling.go @@ -4,9 +4,9 @@ import "strings" // MainSite returns homepage address depending on network used. func MainSite(host string) string { - if strings.HasSuffix(host, "i2p") { + if strings.Contains(host, "i2p") { return "http://arav.i2p" - } else if strings.HasSuffix(host, "onion") { + } else if strings.Contains(host, "onion") { return "http://.onion" } @@ -15,12 +15,12 @@ func MainSite(host string) string { // NetworkType detects network based on host suffix, // whether client connected from Tor, I2P or Clearnet. -func NetworkType(host string) string { - if strings.HasSuffix(host, "i2p") { - return "i2p" - } else if strings.HasSuffix(host, "onion") { - return "tor" +func NetworkType(host string) (string, string) { + if strings.Contains(host, "i2p") { + return "i2p", "http" + } else if strings.Contains(host, "onion") { + return "tor", "http" } else { - return "www" + return "www", "https" } }