From 6a0e64dbf50189a54f221a9ce2b28272a462bbb0 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 5 Feb 2023 06:22:28 +0400 Subject: [PATCH] Added GetServiceByHost() func. --- pkg/util/util.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pkg/util/util.go b/pkg/util/util.go index 16df29f..b138014 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -2,9 +2,55 @@ package util import ( "net/http" + "strings" "time" ) +// GetServiceByHost returns a service's URL depending on what type of network +// is accessed (www, i2p, yggdrasil). +func GetServiceByHost(host, service string) string { + if strings.HasSuffix(host, "i2p") { + switch service { + case "radio": + return "http://radio.arav.i2p" + case "files": + return "http://files.arav.i2p" + case "upload": + return "http://upload.arav.i2p" + case "git": + return "http://git.arav.i2p" + default: + return "http://arav.i2p" + } + } else if strings.HasPrefix(host, "[300") { + switch service { + case "radio": + return "http://[300:a98d:d6d0:8a08::e]" + case "files": + return "http://[300:a98d:d6d0:8a08::d]" + case "upload": + return "http://[300:a98d:d6d0:8a08::c]" + case "git": + return "http://[300:a98d:d6d0:8a08::b]" + default: + return "http://[300:a98d:d6d0:8a08::f]" + } + } else { + switch service { + case "radio": + return "https://radio.arav.top" + case "files": + return "https://files.arav.top" + case "upload": + return "https://upload.arav.top" + case "git": + return "https://git.arav.top" + default: + return "https://arav.top" + } + } +} + // ToClientTimezone converts given time to timezone set in a // X-Client-Timezone header. If this header is not set, then // converts to UTC.