Skip to content

msztolcman/go-hashids

 
 

Repository files navigation

go-hashids GoDoc

Go (golang) v1 implementation of http://www.hashids.org under MIT License (same as the original implementations)

Original implementations by Ivan Akimov

This version (msztolcman/go-hashids) is extended to handle big.Int type. Please take a look at hashids.EncodeBigInt and hashids.DecodeBigIntWithError methods.

Setup

go get github.com/msztolcman/go-hashids/v2

CLI tool :

go get github.com/msztolcman/go-hashids/v2/cmd/hashid

Example

package main

import "fmt"
import "github.com/msztolcman/go-hashids/v2"

func main() {
	hd := hashids.NewData()
	hd.Salt = "this is my salt"
	hd.MinLength = 30
	h, _ := hashids.NewWithData(hd)
	e, _ := h.Encode([]int{45, 434, 1313, 99})
	fmt.Println(e)
	d, _ := h.DecodeWithError(e)
	fmt.Println(d)
}

Thanks to all the contributors

Let me know if I forgot anyone of course.

Changelog

2021/05/04

  • v2.0.1 - Added module support with /v2 suffix

2017/05/09

  • Changed API
    • New methods now return errors
    • Added sanity check in Decode that makes sure that the salt is consistent

2014/09/13

  • Updated to Hashids v1.0.0 (should be compatible with other implementations, let me know if not, was checked against the Javascript version)
  • Changed API
    • Encrypt/Decrypt are now Encode/Decode
    • HashID is now constructed from HashIDData containing alphabet, salt and minimum length

About

Unofficial copy of Go (golang) implementation of http://www.hashids.org

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%