Files
mtusi2026lab3/internal/service/validate.go
T
Weinmaier_AndrewandClaude Opus 5.5 2e7a80be92 lab3: балансировка, идемпотентность, отказ реплики, трек 1
- X-Instance-Id, обязательный Idempotency-Key (PostgreSQL, одна транзакция)
- HAProxy + 2..N реплик API, readiness/drain по SIGTERM, однократные миграции
- скрипты stop-one/restore/restart/rolling-update/collect-evidence
- трек 1: параметризованный стенд, cmd/bench, оркестратор и анализ
- workflow реального прогона Docker-стенда на GitHub Actions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 17:24:54 +03:00

49 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package service
import (
"regexp"
"strings"
"unicode/utf8"
)
var usernameRe = regexp.MustCompile(`^[a-z0-9_]{3,32}$`)
func validatePassword(s string) bool {
n := utf8.RuneCountInString(s)
return n >= 12 && n <= 128
}
// validateUsername проверяет формат username по README: строго [a-z0-9_]{3,32}.
func validateUsername(s string) bool {
return usernameRe.MatchString(s)
}
// validateDisplayName проверяет display_name: 1–100 Unicode code points,
// не состоит только из пробельных символов.
func validateDisplayName(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateTitle проверяет title чата: 1–100 code points, не только пробелы.
func validateTitle(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 100
}
// validateText проверяет text сообщения: 1–4000 code points, не только пробелы.
// В lab4 появится возможность отправить пустой text, если есть attachment_ids.
func validateText(s string) bool {
if strings.TrimSpace(s) == "" {
return false
}
n := utf8.RuneCountInString(s)
return n >= 1 && n <= 4000
}