2 Star 0 Fork 0

TeamsHub/backend-gopkg

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
hash_hashids.go 677 Bytes
Copy Edit Raw Blame History
HCY authored 2024-05-10 12:41 +08:00 . c
package hash
import (
"github.com/speps/go-hashids"
)
func (h *hash) HashidsEncode(params []int) (string, error) {
hd := hashids.NewData()
hd.Salt = h.secret
hd.MinLength = h.length
hashID, err := hashids.NewWithData(hd)
if err != nil {
return "", err
}
hashStr, err := hashID.Encode(params)
if err != nil {
return "", err
}
return hashStr, nil
}
func (h *hash) HashidsDecode(hash string) ([]int, error) {
hd := hashids.NewData()
hd.Salt = h.secret
hd.MinLength = h.length
hashID, err := hashids.NewWithData(hd)
if err != nil {
return nil, err
}
ids, err := hashID.DecodeWithError(hash)
if err != nil {
return nil, err
}
return ids, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzheng0709/backend-gopkg.git
git@gitee.com:wuzheng0709/backend-gopkg.git
wuzheng0709
backend-gopkg
backend-gopkg
v1.5.9

Search