nip61: perhaps simplify the function signature and support specific source mints.
This commit is contained in:
13
utils.go
13
utils.go
@@ -5,6 +5,7 @@ import (
|
||||
"cmp"
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// IsValidRelayURL checks if a URL is a valid relay URL (ws:// or wss://).
|
||||
@@ -46,3 +47,15 @@ func CompareEventReverse(b, a Event) int {
|
||||
}
|
||||
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||
}
|
||||
|
||||
// AppendUnique adds items to an array only if they don't already exist in the array.
|
||||
// Returns the modified array.
|
||||
func AppendUnique[I comparable](arr []I, item ...I) []I {
|
||||
for _, item := range item {
|
||||
if slices.Contains(arr, item) {
|
||||
return arr
|
||||
}
|
||||
arr = append(arr, item)
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user