mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-07 22:59:54 +02:00
add NormalizeOKMessage() helper.
This commit is contained in:
12
normalize.go
12
normalize.go
@ -5,7 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NormalizeURL normalizes the url and replaces http://, https:// schemes by ws://, wss://.
|
// NormalizeURL normalizes the url and replaces http://, https:// schemes with ws://, wss://
|
||||||
|
// and normalizes the path.
|
||||||
func NormalizeURL(u string) string {
|
func NormalizeURL(u string) string {
|
||||||
if u == "" {
|
if u == "" {
|
||||||
return ""
|
return ""
|
||||||
@ -32,3 +33,12 @@ func NormalizeURL(u string) string {
|
|||||||
|
|
||||||
return p.String()
|
return p.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NormalizeOKMessage takes a string message that is to be sent in an `OK` or `CLOSED` command
|
||||||
|
// and prefixes it with "<prefix>: " if it doesn't already have an acceptable prefix.
|
||||||
|
func NormalizeOKMessage(reason string, prefix string) string {
|
||||||
|
if idx := strings.Index(reason, ": "); idx == -1 || strings.IndexByte(reason[0:idx], ' ') != -1 {
|
||||||
|
return prefix + ": " + reason
|
||||||
|
}
|
||||||
|
return reason
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user