Decode 解码字符串为数字ID
(encoded string)
| 101 | |
| 102 | // Decode 解码字符串为数字ID |
| 103 | func (h *HashidsManager) Decode(encoded string) (int64, error) { |
| 104 | if encoded == "" { |
| 105 | return 0, errors.New("encoded string cannot be empty") |
| 106 | } |
| 107 | |
| 108 | decoded := h.sqids.Decode(encoded) |
| 109 | if len(decoded) == 0 { |
| 110 | return 0, errors.New("failed to decode string") |
| 111 | } |
| 112 | |
| 113 | return int64(decoded[0]), nil |
| 114 | } |
| 115 | |
| 116 | // EncodeMultiple 编码多个数字ID |
| 117 | func (h *HashidsManager) EncodeMultiple(ids []int64) (string, error) { |
no test coverage detected