1
0

Host can have :port attached, so it is better to check if string contains rather ends with a particular TLD.

This commit is contained in:
Alexander Andreev 2022-02-08 19:00:37 +04:00
parent 7b5b9a7ce8
commit ffe60bae85
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -4,9 +4,9 @@ import "strings"
// MainSite returns homepage address depending on network used. // MainSite returns homepage address depending on network used.
func MainSite(host string) string { func MainSite(host string) string {
if strings.HasSuffix(host, "i2p") { if strings.Contains(host, "i2p") {
return "http://arav.i2p" return "http://arav.i2p"
} else if strings.HasSuffix(host, "onion") { } else if strings.Contains(host, "onion") {
return "http://.onion" return "http://.onion"
} }
@ -15,12 +15,12 @@ func MainSite(host string) string {
// NetworkType detects network based on host suffix, // NetworkType detects network based on host suffix,
// whether client connected from Tor, I2P or Clearnet. // whether client connected from Tor, I2P or Clearnet.
func NetworkType(host string) string { func NetworkType(host string) (string, string) {
if strings.HasSuffix(host, "i2p") { if strings.Contains(host, "i2p") {
return "i2p" return "i2p", "http"
} else if strings.HasSuffix(host, "onion") { } else if strings.Contains(host, "onion") {
return "tor" return "tor", "http"
} else { } else {
return "www" return "www", "https"
} }
} }