From e0e1a775bcf1a42e5a220cae1f07e466f87d444c Mon Sep 17 00:00:00 2001 From: Gustavo Maronato Date: Sat, 19 Aug 2023 12:04:28 -0300 Subject: [PATCH] reduce default short values --- internal/service/short/shortservice.go | 4 ++-- internal/util/short/alphabet.go | 3 --- internal/util/short/generator.go | 14 ++++++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) delete mode 100644 internal/util/short/alphabet.go diff --git a/internal/service/short/shortservice.go b/internal/service/short/shortservice.go index bc2a5f0..bbcf0ed 100644 --- a/internal/service/short/shortservice.go +++ b/internal/service/short/shortservice.go @@ -15,11 +15,11 @@ import ( const ( // DefaultShortLength is the default length of the short URL. - DefaultShortLength = 8 + DefaultShortLength = 5 // MinShortLength is the minimum length of the short URL. MinShortLength = 4 // MaxShortLength is the maximum length of the short URL. - MaxShortLength = 32 + MaxShortLength = 20 ) type ShortService struct { diff --git a/internal/util/short/alphabet.go b/internal/util/short/alphabet.go deleted file mode 100644 index 29e47f6..0000000 --- a/internal/util/short/alphabet.go +++ /dev/null @@ -1,3 +0,0 @@ -package shortutil - -const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" // 64 possibilities diff --git a/internal/util/short/generator.go b/internal/util/short/generator.go index 6718568..a2e27c6 100644 --- a/internal/util/short/generator.go +++ b/internal/util/short/generator.go @@ -3,16 +3,22 @@ package shortutil import ( "math/rand" + "strconv" "strings" "time" ) -const ( - letterIdxBits = 7 // 7 bits to represent a letter index - letterIdxMask = 1<