From d1d57a886aa7e3ef6092b70ceab077e35ee8e0ce Mon Sep 17 00:00:00 2001 From: Remi Gillig Date: Sat, 20 Feb 2016 10:43:42 +0000 Subject: [PATCH] Update README.md and add deprecation to methods that panic. --- README.md | 33 +++++++++++++++++++++++---------- hashids.go | 2 ++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8496214..1960502 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ func main() { h := hashids.NewWithData(hd) e, _ := h.Encode([]int{45, 434, 1313, 99}) fmt.Println(e) - d := h.Decode(e) + d, _ := h.DecodeWithError(e) fmt.Println(d) } ``` @@ -31,15 +31,28 @@ func main() { ### Test results ``` -=== RUN TestEncryptDecrypt ---- PASS: TestEncryptDecrypt (0.00 seconds) - hashids_test.go:21: [45 434 1313 99] -> woQ2vqjnG7nnhzEsDkiYadKa3O71br -> [45 434 1313 99] -=== RUN TestDefaultLength ---- PASS: TestDefaultLength (0.00 seconds) - hashids_test.go:47: [45 434 1313 99] -> 7nnhzEsDkiYa -> [45 434 1313 99] -=== RUN TestCustomAlphabet ---- PASS: TestCustomAlphabet (0.00 seconds) - hashids_test.go:74: [45 434 1313 99] -> MAkhkloFAxAoskax -> [45 434 1313 99] +=== RUN TestEncryptDecrypt +--- PASS: TestEncryptDecrypt (0.00s) + hashids_test.go:22: [45 434 1313 99] -> woQ2vqjnG7nnhzEsDkiYadKa3O71br -> [45 434 1313 99] +=== RUN TestEncryptDecryptInt64 +--- PASS: TestEncryptDecryptInt64 (0.00s) + hashids_test.go:49: [45 434 1313 99 9223372036854775807] -> ZvGlaahBptQNfPOuPjJ51zO3wVzP01 -> [45 434 1313 99 9223372036854775807] +=== RUN TestEncryptWithKnownHash +--- PASS: TestEncryptWithKnownHash (0.00s) + hashids_test.go:75: [45 434 1313 99] -> 7nnhzEsDkiYa +=== RUN TestDecryptWithKnownHash +--- PASS: TestDecryptWithKnownHash (0.00s) + hashids_test.go:92: 7nnhzEsDkiYa -> [45 434 1313 99] +=== RUN TestDefaultLength +--- PASS: TestDefaultLength (0.00s) + hashids_test.go:115: [45 434 1313 99] -> 7nnhzEsDkiYa -> [45 434 1313 99] +=== RUN TestMinLength +--- PASS: TestMinLength (0.00s) +=== RUN TestCustomAlphabet +--- PASS: TestCustomAlphabet (0.00s) + hashids_test.go:150: [45 434 1313 99] -> MAkhkloFAxAoskax -> [45 434 1313 99] +=== RUN TestDecryptWithError +--- PASS: TestDecryptWithError (0.00s) PASS ``` diff --git a/hashids.go b/hashids.go index e19515e..6d8cec1 100644 --- a/hashids.go +++ b/hashids.go @@ -197,6 +197,7 @@ func (h *HashID) EncodeInt64(numbers []int64) (string, error) { return string(result), nil } +// DEPRECATED: Use DecryptWithError instead // Decode unhashes the string passed to an array of int. // It is symmetric with Encode if the Alphabet and Salt are the same ones which were used to hash. // MinLength has no effect on Decode. @@ -223,6 +224,7 @@ func (h *HashID) DecodeWithError(hash string) ([]int, error) { return result, nil } +// DEPRECATED: Use DecryptInt64WithError instead // DecodeInt64 unhashes the string passed to an array of int64. // It is symmetric with EncodeInt64 if the Alphabet and Salt are the same ones which were used to hash. // MinLength has no effect on DecodeInt64.