Code Monkey home page Code Monkey logo

nanoid's Issues

invalid operation

../github.com/aidarkhanov/nanoid/nanoid.go:32:11: invalid operation: 2 << (31 - bits.LeadingZeros32(uint32(len(alphabet) - 1 | 1))) (shift count type int, must be unsigned integer)

It's give me this error when I try to get package with go get github.com/aidarkhanov/nanoid
It was working before this commit b8b9271

Invalid alphabet string

Hello!

I am trying read your implementation and docs (I want to generate identifiers only from symbols) - I found it and all right.

But in your README (you just copy that string, I know :)) you wrote that nanoid used more characters than UUID. I decide to compare your source code and original and found that you used different strings in default mode:

  • you are used string alphabet = "-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW"
  • from original repository let urlAlphabet = 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW'

It is not a problem - I can specify it by myself via Generate, for example. But I think that all general implementation should work the same as original.

And I think that you should rewrite your code like:

// GenerateString generates a random string based on
// alphabet and size.
func GenerateString(alphabet string, size int) (string, error) {
	id, err := FormatString(generateRandomBuffer, alphabet, size)
	if err != nil {
		return "", err
	}
	return id, nil
}

// New generates a random string.
func New() (string, error) {
	return GenerateString(alphabet, size)
}

Because the original code looks like duplicate logic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.