utils

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUUIDv7

func GenerateUUIDv7() uuid.UUID

GenerateUUIDv7 generates a new UUIDv7

func GenerateUUIDv7WithOffset

func GenerateUUIDv7WithOffset(offset time.Duration) uuid.UUID

GenerateUUIDv7WithOffset generates UUIDv7 with time offset from current time

func GenerateUUIDv7WithTime

func GenerateUUIDv7WithTime(t time.Time) uuid.UUID

GenerateUUIDv7WithTime generates UUIDv7 with specific time according to RFC 9562 The first 48 bits contain the timestamp in milliseconds since Unix epoch The next 16 bits contain version (7) and variant The remaining 74 bits contain random data

func GenerateUUIDv7WithUnixTimestamp

func GenerateUUIDv7WithUnixTimestamp(timestamp int64) uuid.UUID

GenerateUUIDv7WithUnixTimestamp generates UUIDv7 from Unix timestamp in milliseconds

func IsUUIDv7

func IsUUIDv7(id uuid.UUID) bool

IsUUIDv7 checks if a UUID is version 7

func IsUUIDv7TimeValid

func IsUUIDv7TimeValid(id uuid.UUID) bool

IsUUIDv7TimeValid checks if the time embedded in UUIDv7 is within valid range

func IsValidUUIDv7

func IsValidUUIDv7(s string) bool

IsValidUUIDv7 checks if a string is a valid UUIDv7

func MustParseUUIDv7

func MustParseUUIDv7(s string) uuid.UUID

MustParseUUIDv7 parses a string into UUIDv7, panics if not valid

func ParseUUIDv7

func ParseUUIDv7(s string) (uuid.UUID, error)

ParseUUIDv7 parses a string into UUIDv7, returns error if not valid UUIDv7

func ParseUUIDv7Time

func ParseUUIDv7Time(id uuid.UUID) (time.Time, error)

ParseUUIDv7Time extracts timestamp from UUIDv7 according to RFC 9562 Returns the timestamp embedded in the first 48 bits

func UUIDv7Batch

func UUIDv7Batch(count int) ([]uuid.UUID, error)

UUIDv7Batch generates a batch of UUIDv7s

func UUIDv7BatchWithTime

func UUIDv7BatchWithTime(t time.Time, count int) ([]uuid.UUID, error)

UUIDv7BatchWithTime generates a batch of UUIDv7s with specific time

func UUIDv7Cursor

func UUIDv7Cursor(id uuid.UUID) string

UUIDv7Cursor creates a cursor string from UUIDv7 for pagination

func UUIDv7FromBytes

func UUIDv7FromBytes(b []byte) (uuid.UUID, error)

UUIDv7FromBytes creates UUIDv7 from byte slice

func UUIDv7FromCursor

func UUIDv7FromCursor(cursor string) (uuid.UUID, error)

UUIDv7FromCursor creates UUIDv7 from cursor string

func UUIDv7FromTimeRange

func UUIDv7FromTimeRange(start, end time.Time) (uuid.UUID, error)

UUIDv7FromTimeRange generates UUIDv7 within a time range

func UUIDv7Sortable

func UUIDv7Sortable(id1, id2 uuid.UUID) bool

UUIDv7Sortable returns true if UUIDv7s are sortable by time

func UUIDv7TimeDifference

func UUIDv7TimeDifference(id1, id2 uuid.UUID) (time.Duration, error)

UUIDv7TimeDifference calculates the time difference between two UUIDv7s

func UUIDv7TimeRange

func UUIDv7TimeRange() (time.Time, time.Time)

UUIDv7TimeRange returns the time range for UUIDv7 generation

func UUIDv7ToBytes

func UUIDv7ToBytes(id uuid.UUID) ([]byte, error)

UUIDv7ToBytes converts UUIDv7 to byte slice

Types

type UUIDv7Validator

type UUIDv7Validator struct {
	AllowNil  bool
	CheckTime bool
	TimeRange time.Duration
}

UUIDv7Validator validates UUIDv7 properties

func NewUUIDv7Validator

func NewUUIDv7Validator() *UUIDv7Validator

NewUUIDv7Validator creates a new UUIDv7 validator

func (*UUIDv7Validator) Validate

func (v *UUIDv7Validator) Validate(id uuid.UUID) error

Validate validates a UUIDv7

func (*UUIDv7Validator) ValidateString

func (v *UUIDv7Validator) ValidateString(s string) error

ValidateString validates a UUIDv7 string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL