shortuuid icon indicating copy to clipboard operation
shortuuid copied to clipboard

UUIDv7

Open ptman opened this issue 1 year ago • 5 comments

Please support UUIDv7, the best thing to have happened for UUID in a very long time.

ptman avatar Dec 04 '24 14:12 ptman

you can do

u, _ := uuid.NewV7()
str := shortuuid.DefaultEncoder.Encode(u)
fmt.Println(str)  // 2HzMQ9tmpRM37k5Cp52uS8

as a workaround

anatoly-kussul avatar Dec 05 '24 16:12 anatoly-kussul

I wonder if the easiest solution for this would be to just introduce a new shortuuid.NewV7() package level function 🤔

lithammer avatar Jan 05 '25 20:01 lithammer

Hey everyone! 👋 I've introduced a package-level shortuuid.NewV7() function that supports UUIDv7. In addition, I've also added encoding support for Namespace, Alphabet etc.

Requesting review. 👀 @lithammer

ashwingopalsamy avatar Jan 11 '25 04:01 ashwingopalsamy

i am unable to Decode a uuid v7 shortuuid.

uuid v7 -> shortuuid -> decode (should give me the same uuid).

debuggerpk avatar Nov 20 '25 12:11 debuggerpk

i am unable to Decode a uuid v7 shortuuid.

uuid v7 -> shortuuid -> decode (should give me the same uuid).

@debuggerpk Can you provide more details or examples?

It's working fine for me

u, _ := uuid.NewV7()
fmt.Println(u.String()) // 019aa24c-fd88-74f5-a58c-28739af06bee
str := shortuuid.DefaultEncoder.Encode(u)
fmt.Println(str) // 2JHFghYTjt3mkie6XNysCt
decoded, _ := shortuuid.DefaultEncoder.Decode(str)
fmt.Println(decoded.String()) // 019aa24c-fd88-74f5-a58c-28739af06bee

anatoly-kussul avatar Nov 20 '25 17:11 anatoly-kussul