The function doesn't do what it's meant to. hash.Sum(bytes) is not generating a hash of the 4 random bytes, but rather generating a constant hash of empty data and appending it to the four random bytes.
Besides this bug in the code, though, the general idea of taking a hash of the 4 random bytes is odd. It adds no entropy and only serves to make the id longer and unwieldy.
I'd suggest replacing this with a call to stdlib uuid.
Database instance names all look like the following:
Note that only the first eight characters change. The remaining are all identical:
d41d8cd98f00b204e9800998ecf8427e
This is because the bytes are generated with this function:
https://github.com/peterldowns/pgtestdb/blob/063644d773d90046da7a77d1cf96f0e766758570/internal/withdb/withdb.go#L63
The function doesn't do what it's meant to.
hash.Sum(bytes)
is not generating a hash of the 4 random bytes, but rather generating a constant hash of empty data and appending it to the four random bytes.Besides this bug in the code, though, the general idea of taking a hash of the 4 random bytes is odd. It adds no entropy and only serves to make the id longer and unwieldy.
I'd suggest replacing this with a call to stdlib
uuid
.