generate short unique ids from integers
译文:从整数生成短唯一ID
文档
- 官网:https://hashids.org/go/
- github: https://github.com/speps/go-hashids
- pkg: https://pkg.go.dev/github.com/speps/go-hashids/v2
安装
go get github.com/speps/go-hashids/v2
示例
package main import ( "fmt" "github.com/speps/go-hashids/v2" ) func main() { hashID, _ := hashids.New() id, _ := hashID.Encode([]int{1, 2, 3}) fmt.Printf("id: %v\n", id) // id: o2fXhV numbers := hashID.Decode(id) fmt.Printf("numbers: %v\n", numbers) // numbers: [1 2 3] }
参考