generate short unique ids from integers

译文:从整数生成短唯一ID

文档

安装

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]
}

参考
​​​「Go工具箱」一个将非负整数转换成唯一、无序ID的工具:hashids​