mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
3d65529d2e
Исправлена опечатка в тесте Разделена логика метода BuildNonElyTexturesHash
36 lines
726 B
Go
36 lines
726 B
Go
package tools
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
"crypto/md5"
|
|
"strconv"
|
|
"encoding/hex"
|
|
)
|
|
|
|
func ParseUsername(username string) string {
|
|
const suffix = ".png"
|
|
if strings.HasSuffix(username, suffix) {
|
|
username = strings.TrimSuffix(username, suffix)
|
|
}
|
|
|
|
return username
|
|
}
|
|
|
|
func BuildNonElyTexturesHash(username string) string {
|
|
hour := getCurrentHour()
|
|
hasher := md5.New()
|
|
hasher.Write([]byte("non-ely-" + strconv.FormatInt(hour, 10) + "-" + username))
|
|
|
|
return hex.EncodeToString(hasher.Sum(nil))
|
|
}
|
|
|
|
func BuildKey(username string) string {
|
|
return "username:" + strings.ToLower(username)
|
|
}
|
|
|
|
func getCurrentHour() int64 {
|
|
n := time.Now()
|
|
return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix()
|
|
}
|