move stuff back from nostr package to top level.

because otherwise the path must be specified as github.com/fiatjaf/go-nostr/nostr, which is annoying.
This commit is contained in:
fiatjaf
2022-11-04 08:22:12 -03:00
parent 3a6d6795e4
commit 329b8d44d2
12 changed files with 0 additions and 0 deletions

28
normalize.go Normal file
View File

@@ -0,0 +1,28 @@
package nostr
import (
"net/url"
"strings"
)
func NormalizeURL(u string) string {
if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
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]
}
return p.String()
}