mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-24 17:39:58 +02:00
CompareEvent() for helping with slices.BinarySearch()
This commit is contained in:
parent
87e696eecb
commit
a54852f439
8
utils.go
8
utils.go
@ -1,6 +1,7 @@
|
|||||||
package nostr
|
package nostr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -27,3 +28,10 @@ func IsValid32ByteHex(thing string) bool {
|
|||||||
_, err := hex.DecodeString(thing)
|
_, err := hex.DecodeString(thing)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CompareEvent(a, b Event) int {
|
||||||
|
if a.CreatedAt == b.CreatedAt {
|
||||||
|
return strings.Compare(a.ID, b.ID)
|
||||||
|
}
|
||||||
|
return cmp.Compare(a.CreatedAt, b.CreatedAt)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user