google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.24k stars 363 forks source link

Is there a method to generate empty UUID v4? #104

Closed fulviodenza closed 1 year ago

fulviodenza commented 2 years ago

Hi! I noticed there is a uuid.Nil for UUID v1 but no uuid.Nil (for example uuid.Nil4) for UUID v4 could be useful adding this method to the library? (I could also make a PR)

alexis-coulombe commented 1 year ago

There's no difference in format between a v1 or v4, you could probably use this to generate an empty uuid https://github.com/google/uuid/blob/44b5fee7c49cf3bcdf723f106b36d56ef13ccc88/hash.go#L19

https://www.sohamkamani.com/uuid-versions-explained/#how-are-uuids-structured

pborman commented 1 year ago

Alexi is correct.

But just to be clear, the uuid.Nil is nil for every version (all zeros). v1 and v4 UUIDs themselves are very different in how the bits are computed and treated.

On Jul 28, 2023, at 5:22 PM, Alexis Coulombe @.***> wrote:

There's no difference in format between a v1 or v4, you could probably use this https://github.com/google/uuid/blob/44b5fee7c49cf3bcdf723f106b36d56ef13ccc88/hash.go#L19 so generate an empty uuid

https://www.sohamkamani.com/uuid-versions-explained/#how-are-uuids-structured

— Reply to this email directly, view it on GitHub https://github.com/google/uuid/issues/104#issuecomment-1656396276, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHBAHMBXDMA6GBLJEYNRTLXSQ3STANCNFSM5Y3FN6IQ. You are receiving this because you are subscribed to this thread.