Fixed database migration, imporved logging, imporved hashing function,

introduced connection pooling instead of single conncetion.
This commit is contained in:
Andrej Mickov
2025-08-07 20:45:18 +02:00
parent e178613607
commit f27f1fc3d6
7 changed files with 211 additions and 85 deletions

View File

@@ -2,16 +2,13 @@ package utils
import (
"crypto/sha256"
"fmt"
)
const base62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
func GenerateUrlHash(url string) string {
encoded := EncodeToBase62(url)
hash := sha256.Sum256([]byte(encoded))
return fmt.Sprintf("%x", hash)
hash := sha256.Sum256([]byte(url))
return EncodeToBase62(string(hash[:]))
}
func EncodeToBase62(url string) string {
@@ -21,9 +18,8 @@ func EncodeToBase62(url string) string {
for _, b := range hash[:] {
encoded += string(base62[int(b)%62])
}
if len(encoded) > 6 {
encoded = encoded[:6]
if len(encoded) > 7 {
return encoded[:7]
}
return encoded
}