CompareEvent() for helping with slices.BinarySearch()

This commit is contained in:
fiatjaf 2024-09-15 12:57:51 -03:00
parent 87e696eecb
commit a54852f439

View File

@ -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)
}