refactor(auth): extract timestamp validation to separate function

Move timestamp validation logic from handlers to ValidateTimeStamp function in auth.go to avoid code duplication and improve maintainability
This commit is contained in:
2026-02-27 21:21:18 +08:00
parent 852f13fa61
commit 1eb9351604
2 changed files with 17 additions and 12 deletions
+11 -3
View File
@@ -19,9 +19,9 @@ type TokenInfo struct {
}
var (
tokenMap = make(map[int]*TokenInfo)
tokenMux sync.RWMutex
tokenTTL = time.Hour
tokenMap = make(map[int]*TokenInfo)
tokenMux sync.RWMutex
tokenTTL = time.Hour
)
func GenerateToken(userID int) (string, error) {
@@ -168,3 +168,11 @@ func isValidPassword(password string) bool {
return hasUpper && hasLower && hasDigit && hasSpecial
}
func ValidateTimeStamp(timeStamp int64) error {
currentTime := time.Now().UnixMilli()
if !globalConfig.Debug && (currentTime-timeStamp > 3000 || timeStamp-currentTime > 3000) {
return errors.New("timestamp out of valid range")
}
return nil
}