12345678910111213141516171819202122232425262728 |
- package jwt
- import "github.com/speps/go-hashids/v2"
- var salt = "fastgpthashids"
- func HashidsEncode(num int) string {
- hd := hashids.NewData()
- hd.Salt = salt
- hd.MinLength = 20
- h, _ := hashids.NewWithData(hd)
- e, _ := h.Encode([]int{num})
- return e
- }
- func HashidsDecode(hashidstr string) int {
- hd := hashids.NewData()
- hd.Salt = salt
- hd.MinLength = 20
- h, _ := hashids.NewWithData(hd)
- numbs, err := h.DecodeWithError(hashidstr)
- if err != nil {
- return -1
- }
- return numbs[0]
- }
|