plakken/utils.go

38 lines
658 B
Go
Raw Normal View History

2023-10-02 20:33:13 +02:00
package main
import (
"crypto/rand"
"encoding/hex"
mathrand "math/rand"
)
2023-10-02 20:33:13 +02:00
func generateUrl() string {
length := currentConfig.urlLength
listChars := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
b := make([]rune, length)
for i := range b {
b[i] = listChars[mathrand.Intn(len(listChars))]
2023-10-02 20:33:13 +02:00
}
return string(b)
}
func generateSecret() string {
key := make([]byte, 32)
_, err := rand.Read(key)
if err != nil {
// handle error here
}
secret := hex.EncodeToString(key)
return secret
}
func urlExist(url string) bool {
exist := connectDB().Exists(ctx, url).Val()
if exist == 1 {
return true
}
return false
}