hashids.go 489 B

12345678910111213141516171819202122232425262728
  1. package jwt
  2. import "github.com/speps/go-hashids/v2"
  3. var salt = "fastgpthashids"
  4. func HashidsEncode(num int) string {
  5. hd := hashids.NewData()
  6. hd.Salt = salt
  7. hd.MinLength = 20
  8. h, _ := hashids.NewWithData(hd)
  9. e, _ := h.Encode([]int{num})
  10. return e
  11. }
  12. func HashidsDecode(hashidstr string) int {
  13. hd := hashids.NewData()
  14. hd.Salt = salt
  15. hd.MinLength = 20
  16. h, _ := hashids.NewWithData(hd)
  17. numbs, err := h.DecodeWithError(hashidstr)
  18. if err != nil {
  19. return -1
  20. }
  21. return numbs[0]
  22. }