adapt relaypool to the new nip-01.

This commit is contained in:
fiatjaf
2021-02-20 17:44:05 -03:00
parent ee53d55800
commit 4a172a5f51
4 changed files with 172 additions and 128 deletions
+7 -11
View File
@@ -7,26 +7,22 @@ import (
func NormalizeURL(u string) string {
if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
u = "ws://" + u
u = "wss://" + u
}
p, err := url.Parse(u)
if err != nil {
return ""
}
if p.Scheme == "http" {
p.Scheme = "ws"
} else if p.Scheme == "https" {
p.Scheme = "wss"
}
if strings.HasSuffix(p.RawPath, "/") {
p.RawPath = p.RawPath[0 : len(p.RawPath)-1]
}
if strings.HasSuffix(p.RawPath, "/ws") {
p.RawPath = p.RawPath[0 : len(p.RawPath)-3]
}
return p.String()
}
func WebsocketURL(u string) string {
p, _ := url.Parse(NormalizeURL(u))
p.RawPath += "/ws"
return p.String()
}