Ordering UUID V1 bytes by inserted timestamp for practical purposes. If you want to store UUID's sequentially in databases, you can use this library.
Go 1.14 ~ 1.15, other versions not tested
Add it in your project: go get github.com/MufidJamaluddin/uuidv1_orderer
- Ordering Existing UUID's
unorderedUuid := UUIDStringToBytes("c5db1800-ce4c-11de-a5e2-1b45123c6e98")
orderedUuid := ToOrderedUuid(unorderedUuid)
orderedUuidStr := UUIDBytesToString(orderedUuid)
// next, your logic
- Transform Back to Standard UUID V1
orderedUuid := UUIDStringToBytes("11dece4c-c5db-1800-a5e2-1b45123c6e98")
standardUuidV1 := FromOrderedUuid(orderedUuid)
standardUuidV1Str := UUIDBytesToString(standardUuidV1)
// next, your logic
The differences explanation between ordered and standard UUID V1 is bellow
Example: c5db1800-ce4c-11de-a5e2-1b45123c6e98
Meaning:
- Timestamp
1de-ce4c-c5db1800
inc5db1800-ce4c-11de
- Standard UUID version
1
inc5db1800-ce4c-(1)1de
- Clock sequence
a5e2
- Standard MAC Address or Nonstandard Random IDs
1b45123c6e98
Reorder timestamp to it's origin form with UUID version on top.
Example: 11dece4c-c5db-1800-a5e2-1b45123c6e98
(c) Mufid Jamaluddin. MIT Licenses