Skip to content

Use uint64 instead of int64 #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kzys opened this issue Jan 25, 2024 · 0 comments
Open

Use uint64 instead of int64 #64

kzys opened this issue Jan 25, 2024 · 0 comments

Comments

@kzys
Copy link

kzys commented Jan 25, 2024

go-hashids provides EncodeInt64 but it actually rejects negative numbers in below. Does it make sense to use uint64, or provides a uint64 variant?

// EncodeInt64 hashes an array of int64 to a string containing at least MinLength characters taken from the Alphabet.
// Use DecodeInt64 using the same Alphabet and Salt to get back the array of int64.
func (h *HashID) EncodeInt64(numbers []int64) (string, error) {
	if len(numbers) == 0 {
		return "", errors.New("encoding empty array of numbers makes no sense")
	}
	for _, n := range numbers {
		if n < 0 {
			return "", errors.New("negative number not supported")
		}
	}

I'm using go-hashids along with hashids' Ruby implementation. In some cases, go-hashids rejects inputs that exceed MaxInt, while the Ruby implementation can handle it because Ruby's Integer can be larger than Go's MaxInt.

I made a fork to workaround the issue and happy to upstream something like this.

https://github.com/kzys/go-hashids/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant