Full refactor of codebase

This commit is contained in:
Jonas Hahn
2025-09-18 16:51:57 +02:00
parent 0e6e48cd7b
commit 4168e92601
34 changed files with 1176 additions and 1062 deletions

42
src/utils/utils.go Normal file
View File

@@ -0,0 +1,42 @@
package utils
import (
"crypto/rand"
"encoding/hex"
"math"
"strings"
"time"
)
func Now() time.Time {
return time.Now().UTC()
}
func StripAfterDot(s string) string {
if idx := strings.Index(s, "."); idx != -1 {
return s[:idx]
}
return s
}
func NameFromEmail(email string) string {
parts := strings.SplitN(email, "@", 2)
if len(parts) > 0 {
return parts[0]
}
return ""
}
func RoundFloat(val float64, precision uint) float64 {
ratio := math.Pow(10, float64(precision))
return math.Round(val*ratio) / ratio
}
func MustRandToken(n int) string {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
panic(err)
}
return hex.EncodeToString(b)
}