
Show HN: Go library for concise, unambiguous and URL-safe UUIDs - Spiritus
https://github.com/renstrom/shortuuid
======
shawnps
Ran it through an app I maintain, Go Report Card, and it got an A+ grade:
[http://goreportcard.com/report/renstrom/shortuuid](http://goreportcard.com/report/renstrom/shortuuid)

I'm actually pretty surprised, as I do this quite often and it's rare that
something gets 100% across the board on the first try. Not that it's
necessarily difficult, but I find people normally don't use all 3 of "gofmt
-s", "golint", and "go vet". Anyway, nicely done.

~~~
anonfunction
I use gometalinter which runs it through a whole suite of linters.

------
thwarted
The goals of unambiguous and concise are at odds, and this format (well, the
defaults) errs on the side of shorter.

To lessen ambiguity even more, there's Crockford Encoding[0]. Results in
longer strings, but there's no case distinction, and the similar looking
characters decode the same. Looks like you can get mostly Crockford Encoding
using this library by changing the character set (which is why said "the
defaults" above). The check digit in Crockford Encoding is a huge win for when
these are dictated/transcribed, but may need to be URL-encoded.

[0]
[http://www.crockford.com/wrmg/base32.html](http://www.crockford.com/wrmg/base32.html)

~~~
Spiritus
That's interesting. I will definitely see if I can incorporate it somehow,
even if it's just a note in the README.

------
swah
My Go is rusty, but this look a little error prone:

    
    
        // Note that this will create a new UUID each time its .String() method
        // is invoked.
        fmt.Printf("%s", u)  // Cekw67uyMpBGZLRP2HFVbe
        fmt.Printf("%s", u)  // 4pUYNRFHTG3YVgThPZvCgC
    

Just imagine an user using u directly instead of assigning to a var:

    
    
        token := "secret" + u
        othertoken := "app" + u

~~~
Spiritus
Author here. Yes, this is indeed a terrible idea! Will definitely fix it.

~~~
Spiritus
Fixed in
[https://github.com/renstrom/shortuuid/commit/847debec9c7c091...](https://github.com/renstrom/shortuuid/commit/847debec9c7c091fdb85d26bfe9111c0be3dca08)

------
Spiritus
As mentioned in the README, it's heavily based on the Python version[1].

[1] [https://github.com/stochastic-
technologies/shortuuid](https://github.com/stochastic-technologies/shortuuid)

------
sdegutis
I thought UUIDs had to be 128 bits, such as
"de305d54-75b4-431b-adb2-eb6b9e546014" (32 x 4-bit characters, not counting
hypens). How is "ajLWxEodc6CmQLHADuKVwD" a UUID?

~~~
hesdeadjim
"de305d54-75b4-431b-adb2-eb6b9e546014" is simply an encoding of a 128 bit
number. This standard hex UUID representation requires 8 bits/character * 36
characters == 288 bytes == 2304 bits. This encoding only requires 22
characters or 1408 bytes, almost half the size.

