matoous / go-nanoid Goto Github PK
View Code? Open in Web Editor NEWGolang random IDs generator.
License: MIT License
Golang random IDs generator.
License: MIT License
Just want to confirm that this package is compatible with v3 nanoid: https://github.com/ai/nanoid/releases/tag/3.0.0
wouldnt it be better to use gonanoid.New()
, gonanoid.Generate()
or if the package had different name generator.Nanoid()
or generator.NewNanoid()
?
New uses bits 0-6 of each random byte (masks with 63) and the two high random bits are discarded.
I think it would be better not to discard randomness.
Lines 89 to 97 in 0cc1b25
It is possible to write a loop and output 4 characters per each 3 random bytes and handle the remainder separately.
Or maybe reuse the base64 encoding code from standard library.
Hello!
I'm migrating from Google's UUID Package, and there is an specific detail that I find odd: the lack of Must
and/or New
on the API. These two functions are useful when you're quickly prototyping or when you DO want the entire world to blown up in case of errors.
These two functions have the following signature:
func Must (id string, err error) string // panics if err is not null
func New() string // returns a new id or panics
Is this feature acceptable? If so, I already made the changes locally on my machine and can send you a PR.
does it possible to get sortable nanoids ?
I try to use this library to generate simple human readable ID's on my native language.
Using library according to documentation with non ascii alphabet:
id, err := gonanoid.Generate("абвгдежиклмнпрстуфхшэюя0123456789-", 10)
Gives me byte garbage with wrong length
3ю�ѽ�д0
�Џ�51�б7
���Ѷ0�Ѻ�
Instead normal ID like:
2юбнг4внеэ
Original implementation has no this problem https://zelark.github.io/nano-id-cc/
If Nanoid()
function is called with a negative argument, the function panics.
E.g.
gonanoid.Nanoid(-1)
panics with:
panic: runtime error: makeslice: len out of range [recovered]
panic: runtime error: makeslice: len out of range
The function signature already allows to return an error so I suggest to return an error in this case instead of letting it panic.
Additionally, due to the (in my opinion not very Go ideomatic) function signature, it is possible to call this function with more than one argument. I suggest to return an error in this case as well.
I can provide a PR if you wish.
This is got into deadlock.
package main
import (
"fmt"
"github.com/matoous/go-nanoid"
)
func main() {
gonanoid.Size(0)
gonanoid.Alphabet("abcdefghijklmnopqrstuvwxyz")
id := gonanoid.Generate()
fmt.Printf("ID: %s", id)
}
And this is got panic.
package main
import (
"fmt"
"github.com/matoous/go-nanoid"
)
func main() {
gonanoid.Alphabet("abcdefghijklmnopqrstuvwxyz")
gonanoid.Size(0)
id := gonanoid.Generate()
fmt.Printf("ID: %s", id)
}
similar error when we are using gonanoid.Alphabet("")
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/lint.yml
actions/checkout v2
golangci/golangci-lint-action v2
.github/workflows/test.yml
actions/setup-go v2
actions/checkout v2
actions/setup-go v2
actions/checkout v2
go.mod
go 1.15
github.com/stretchr/testify v1.7.0
Let’s update the library to be compatible with the latest Nano ID 2.0:
~
to -
in default alphabetnon-secure
fast generatorThis dependency don't working
require (
github.com/matoous/go-nanoid v1.4.0
)
go: github.com/matoous/[email protected]: reading github.com/matoous/go-nanoid/go.mod at revision v1.4.0: unknown revision v1.4.0
But working this.
require (
github.com/matoous/go-nanoid v.1.4.0
)
Which change automatically in my go.mod to:
require (
github.com/matoous/go-nanoid v1.3.1-0.20200518070138-513938f8e67d
)
Hi,
When I go get github.com/matoous/go-nanoid
it retrieves the version 1.5.0.
go: downloading github.com/matoous/go-nanoid v1.5.0
go: github.com/matoous/go-nanoid upgrade => v1.5.0
I would like to use the most recent version (aka 2.0.0) but I'm not sure how to download/add it to my project.
I looked at the primary implementation as well as the implementation for other languages, and the default length for the id is 21. Is there specific reason to make it 22 in this library? In my opinion, it should be consistent with rest of them.
step = int(math.Ceil(1.6 * float64(mask) * float64(size) / float64(len(alphabet))))
According to to formula, step
affected by size
, this means:
Size()
before Alphabet()
, step
's value is correct;Size()
after Alphabet()
, step
's value is incorrect;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.