lithammer / shortuuid Goto Github PK
View Code? Open in Web Editor NEW:mushroom: A generator library for concise, unambiguous and URL-safe UUIDs
Home Page: https://pkg.go.dev/github.com/lithammer/shortuuid/v4
License: MIT License
:mushroom: A generator library for concise, unambiguous and URL-safe UUIDs
Home Page: https://pkg.go.dev/github.com/lithammer/shortuuid/v4
License: MIT License
Hello
I tried the example on README:
package main
import (
"fmt"
"github.com/lithammer/shortuuid/v3"
)
func main() {
u := shortuuid.New() // Cekw67uyMpBGZLRP2HFVbe
}
When I run:
go get -t -v ./...
I got this error:
github.com/lithammer/shortuuid (download)
cannot find package "github.com/lithammer/shortuuid/v3" in any of:
/usr/local/go/src/github.com/lithammer/shortuuid/v3 (from $GOROOT)
/home/marcos/go/src/github.com/lithammer/shortuuid/v3 (from $GOPATH)
but the package is available in: /home/marcos/go/src/github.com/lithammer/shortuuid
what was my mistake?
I don't know why and when, github.com/renstrom/shortuuid has been switched to github.com/lithammer/shortuuid, which make my code dependence failed.
Why not just fork, instead of deleting old account.
Hi,
Disclaimer: I'm not an expert in regards to UUIDs, but I just looked over your code and found this odd thing:
https://github.com/renstrom/shortuuid/blob/bc12e561a2565bb6377569675aa276013f9bc5e3/shortuuid.go#L48
It seems like the DNS and URL Namespaces are swapped.
You check for the http prefix and then assign the DNS namespace.
If this is indented, maybe a comment to explain why this is the case would be helpful.
Cheers,
Christian
In your readme code example will need to update to use Google UUID?
base57.numToString()
uses number.Uint64()
which is undefined if number
"cannot be represented in a uint64" which is the case since it starts off containing a 128 bit integer.
This causes incorrect encoding of any UUID whose low half bits are all zero (along with any other cases where those bits were zero after some number of divisions by b.alphabet.Length()
).
00000000-0000-0000-8000-000000000000
encodes to "z7C8BNkRBVT22", but 00000000-0000-0001-0000-000000000000
erroneously encodes to "2222222222222" which clashes with the encoding of 00000000-0000-0000-0000-000000000000
as opposed to the expected "yDNELiVqLxt22".
After bumping this lib with dep, I get the following error:
vendor/github.com/renstrom/shortuuid/shortuuid.go:21:40: not enough arguments in call to uuid.Must
have (uuid.UUID)
want (uuid.UUID, error)
Seems to affect v2.0.1
It results in a bug, where the first character of the alphabet is always considered as non-present. PR #2 adds an error return value to the function, integrates it with the others and includes tests for this case. Thus fixing this issue.
Seems like base57 is an unnecessary distinction from base58 which already has pretty heavy standardization within Bitcoin and wide library support across languages see:
https://github.com/bitcoin/bitcoin/blob/master/src/base58.cpp#L19
https://github.com/tv42/base58/blob/master/base58.go#L13
https://github.com/keis/base58/blob/master/base58.py#L17
https://github.com/mattallty/base58/blob/master/src/Allty/Utils/Base58.php#L6
https://github.com/jrdnull/base58/blob/master/lib/base58.ex#L2
https://github.com/45678/Base58/blob/master/Base58.coffee#L3
https://github.com/luke-jr/libbase58/blob/master/base58.c#L143
PS C:\Users\Anla-E\Desktop> go get github.com/renstrom/shortuuid
# github.com/renstrom/shortuuid
..\go\src\github.com\renstrom\shortuuid\shortuuid.go:21:30: too many arguments in call to DefaultEncoder.Encode
have (uuid.UUID, error)
want (uuid.UUID)
..\go\src\github.com\renstrom\shortuuid\shortuuid.go:26:19: too many arguments in call to enc.Encode
have (uuid.UUID, error)
want (uuid.UUID)
..\go\src\github.com\renstrom\shortuuid\shortuuid.go:35:17: multiple-value uuid.NewV4() in single-value context
..\go\src\github.com\renstrom\shortuuid\shortuuid.go:49:19: too many arguments in call to enc.Encode
have (uuid.UUID, error)
want (uuid.UUID)
Randomly, the generated UUID length returned using shortuuid.New()
is 21 instead of 22.
Now we can custom alphabets with 57 lengths limited by base57 inside.
Can we support custom character length alphabets? The logic should be similar to base57 except the output length will be changed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.