mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01: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
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"strings"
|
||||
@ -27,3 +28,10 @@ func IsValid32ByteHex(thing string) bool {
|
||||
_, err := hex.DecodeString(thing)
|
||||
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