2022-01-02 08:44:18 -03:00
|
|
|
package nostr
|
2021-01-31 11:05:09 -03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NormalizeURL(u string) string {
|
|
|
|
if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
|
2021-02-20 17:44:05 -03:00
|
|
|
u = "wss://" + u
|
2021-01-31 11:05:09 -03:00
|
|
|
}
|
|
|
|
p, err := url.Parse(u)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2021-02-20 17:44:05 -03:00
|
|
|
if p.Scheme == "http" {
|
|
|
|
p.Scheme = "ws"
|
|
|
|
} else if p.Scheme == "https" {
|
|
|
|
p.Scheme = "wss"
|
2021-01-31 11:05:09 -03:00
|
|
|
}
|
|
|
|
|
2021-02-20 17:44:05 -03:00
|
|
|
if strings.HasSuffix(p.RawPath, "/") {
|
|
|
|
p.RawPath = p.RawPath[0 : len(p.RawPath)-1]
|
2021-01-31 11:05:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return p.String()
|
|
|
|
}
|