-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for UUID Version 8 (RFC 9562) #178
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bormanp, apologies for the noise! I’d really appreciate it if you could take a look at this proposal when you have a moment. Thanks in advance! 🙏
any news ? uuid v8 really useful when need to store in db and have ordered records with uniq node id |
hi team, would appreciate your eyes on this proposal. @quartzmo / @bormanp / @noahdietz :) |
Hello 👋 Would appreciate some review here :) |
version8.go
Outdated
timestamp := uint64(time.Now().UnixNano()) | ||
|
||
timeMu.Lock() | ||
defer timeMu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we release lock after the if
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Sure, I can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not like that. Drop defer
, it's not needed after the if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alrights! done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer
, not mu.Unlock()
version8.go
Outdated
} | ||
|
||
// makeV8 generates a version 8 UUID using user-provided or random data for custom_a, custom_b, and custom_c. | ||
func makeV8(uuid []byte, customA, customB, customC []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes! This wasn't supposed to be here. Removed it.
remove redundant function (dead code) and place the `sync.Mutex` lock after the `if` condition
Changes
This adds support for generating UUID Version 8 as defined in RFC 9562. UUIDv8 is designed for custom or experimental use cases, allowing you to embed application-specific data while adhering to standard version and variant bits.
What’s included:
NewV8()
: Generates a UUIDv8 with random values.NewV8FromReader(customA, customB, r)
: Allows custom values forcustom_a
(48 bits) andcustom_b
(12 bits) whilecustom_c
field (62 bits) is filled using a random source or secure fallback.NewV8TimeBased(r)
: A time-based variant ofUUIDv8
that uses the current timestamp forcustom_a
. It also includes a sequence number to ensure uniqueness when multiple UUIDs are generated in the same nanosecond.This addition completes support for all UUID versions in RFC 9562. Looking forward for your feedback, team!