Skip to content

Commit d1d57a8

Browse files
committed
Update README.md and add deprecation to methods that panic.
1 parent 9aaed95 commit d1d57a8

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

README.md

+23-10
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,36 @@ func main() {
2323
h := hashids.NewWithData(hd)
2424
e, _ := h.Encode([]int{45, 434, 1313, 99})
2525
fmt.Println(e)
26-
d := h.Decode(e)
26+
d, _ := h.DecodeWithError(e)
2727
fmt.Println(d)
2828
}
2929
```
3030

3131
### Test results
3232

3333
```
34-
=== RUN TestEncryptDecrypt
35-
--- PASS: TestEncryptDecrypt (0.00 seconds)
36-
hashids_test.go:21: [45 434 1313 99] -> woQ2vqjnG7nnhzEsDkiYadKa3O71br -> [45 434 1313 99]
37-
=== RUN TestDefaultLength
38-
--- PASS: TestDefaultLength (0.00 seconds)
39-
hashids_test.go:47: [45 434 1313 99] -> 7nnhzEsDkiYa -> [45 434 1313 99]
40-
=== RUN TestCustomAlphabet
41-
--- PASS: TestCustomAlphabet (0.00 seconds)
42-
hashids_test.go:74: [45 434 1313 99] -> MAkhkloFAxAoskax -> [45 434 1313 99]
34+
=== RUN TestEncryptDecrypt
35+
--- PASS: TestEncryptDecrypt (0.00s)
36+
hashids_test.go:22: [45 434 1313 99] -> woQ2vqjnG7nnhzEsDkiYadKa3O71br -> [45 434 1313 99]
37+
=== RUN TestEncryptDecryptInt64
38+
--- PASS: TestEncryptDecryptInt64 (0.00s)
39+
hashids_test.go:49: [45 434 1313 99 9223372036854775807] -> ZvGlaahBptQNfPOuPjJ51zO3wVzP01 -> [45 434 1313 99 9223372036854775807]
40+
=== RUN TestEncryptWithKnownHash
41+
--- PASS: TestEncryptWithKnownHash (0.00s)
42+
hashids_test.go:75: [45 434 1313 99] -> 7nnhzEsDkiYa
43+
=== RUN TestDecryptWithKnownHash
44+
--- PASS: TestDecryptWithKnownHash (0.00s)
45+
hashids_test.go:92: 7nnhzEsDkiYa -> [45 434 1313 99]
46+
=== RUN TestDefaultLength
47+
--- PASS: TestDefaultLength (0.00s)
48+
hashids_test.go:115: [45 434 1313 99] -> 7nnhzEsDkiYa -> [45 434 1313 99]
49+
=== RUN TestMinLength
50+
--- PASS: TestMinLength (0.00s)
51+
=== RUN TestCustomAlphabet
52+
--- PASS: TestCustomAlphabet (0.00s)
53+
hashids_test.go:150: [45 434 1313 99] -> MAkhkloFAxAoskax -> [45 434 1313 99]
54+
=== RUN TestDecryptWithError
55+
--- PASS: TestDecryptWithError (0.00s)
4356
PASS
4457
```
4558

hashids.go

+2
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (h *HashID) EncodeInt64(numbers []int64) (string, error) {
197197
return string(result), nil
198198
}
199199

200+
// DEPRECATED: Use DecryptWithError instead
200201
// Decode unhashes the string passed to an array of int.
201202
// It is symmetric with Encode if the Alphabet and Salt are the same ones which were used to hash.
202203
// MinLength has no effect on Decode.
@@ -223,6 +224,7 @@ func (h *HashID) DecodeWithError(hash string) ([]int, error) {
223224
return result, nil
224225
}
225226

227+
// DEPRECATED: Use DecryptInt64WithError instead
226228
// DecodeInt64 unhashes the string passed to an array of int64.
227229
// It is symmetric with EncodeInt64 if the Alphabet and Salt are the same ones which were used to hash.
228230
// MinLength has no effect on DecodeInt64.

0 commit comments

Comments
 (0)