go-nostr/utils/utils.go

29 lines
447 B
Go
Raw Permalink Normal View History

2021-01-31 11:05:09 -03:00
package nostrutils
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()
}