mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-26 17:52:20 +01:00
add NormalizeOKMessage() helper.
This commit is contained in:
parent
7449f254db
commit
ddc50028c3
12
normalize.go
12
normalize.go
@ -5,7 +5,8 @@ import (
|
||||
"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 {
|
||||
if u == "" {
|
||||
return ""
|
||||
@ -32,3 +33,12 @@ func NormalizeURL(u string) 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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user